-
Notifications
You must be signed in to change notification settings - Fork 108
fix(ci): build linux native library with glibc sysroot #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chsbuffer
wants to merge
1
commit into
LuckyPray:master
Choose a base branch
from
chsbuffer:fix-linux
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,8 @@ | |
| .externalNativeBuild | ||
| .cxx | ||
| local.properties | ||
| .dexkit-sysroot/ | ||
|
|
||
| /docs | ||
| /doc | ||
| /apk | ||
| /apk | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # Linux sysroot builds | ||
|
|
||
| This directory contains helper files for building DexKit Linux binaries against | ||
| older Ubuntu runtime libraries. | ||
|
|
||
| The goal is to keep the generated `libdexkit.so` compatible with the target | ||
| distribution's glibc, libstdc++, and libgcc runtime. Do not add | ||
| `ppa:ubuntu-toolchain-r/test` to the sysroot: the compatibility target is the | ||
| toolchain shipped by the distribution itself. That PPA can upgrade runtime | ||
| packages such as `libstdc++6`, so the sysroot would no longer represent the | ||
| distribution-provided runtime. | ||
|
|
||
| Run the commands from the repository root. `build-linux-sysroot.sh` must run as | ||
| root because `debootstrap` creates device nodes and package metadata inside the | ||
| sysroot. If a sysroot or headers directory already exists, remove it first. | ||
|
|
||
| ## Pack sysroot backups | ||
|
|
||
| After building a sysroot, it can be packed for backup or reuse. Replace the | ||
| path with the target sysroot that was built: | ||
|
|
||
| ```bash | ||
| sudo tar -C .dexkit-sysroot/ubuntu-16.04-x86_64 \ | ||
| --exclude=./dev \ | ||
| --exclude=./proc \ | ||
| --exclude=./sys \ | ||
| --exclude=./run \ | ||
| --exclude=./tmp \ | ||
| --exclude=./var/tmp \ | ||
| -cJf .dexkit-sysroot/ubuntu-16.04-x86_64.tar.xz . | ||
| ``` | ||
|
|
||
| The GCC 10 headers directory can be packed without special excludes: | ||
|
|
||
| ```bash | ||
| tar -C .dexkit-sysroot/gcc10-headers \ | ||
| -cJf .dexkit-sysroot/gcc10-headers.tar.xz . | ||
| ``` | ||
|
|
||
| To unpack a backup: | ||
|
|
||
| ```bash | ||
| rm -rf .dexkit-sysroot/ubuntu-16.04-x86_64 | ||
| mkdir -p .dexkit-sysroot/ubuntu-16.04-x86_64 | ||
| tar -C .dexkit-sysroot/ubuntu-16.04-x86_64 \ | ||
| -xJf .dexkit-sysroot/ubuntu-16.04-x86_64.tar.xz | ||
|
|
||
| rm -rf .dexkit-sysroot/gcc10-headers | ||
| mkdir -p .dexkit-sysroot/gcc10-headers | ||
| tar -C .dexkit-sysroot/gcc10-headers \ | ||
| -xJf .dexkit-sysroot/gcc10-headers.tar.xz | ||
| ``` | ||
|
|
||
| ## Ubuntu 20.04 target | ||
|
|
||
| Ubuntu 20.04 is the baseline C++20 build. Its sysroot includes GCC 10 headers | ||
| and libstdc++. | ||
|
|
||
| ```bash | ||
| sudo env UBUNTU_CODENAME=focal \ | ||
| bash build-support/linux-sysroot/build-linux-sysroot.sh \ | ||
| .dexkit-sysroot/ubuntu-20.04-x86_64 | ||
|
|
||
| SYSROOT="$PWD/.dexkit-sysroot/ubuntu-20.04-x86_64" | ||
|
|
||
| export CC="clang --sysroot=$SYSROOT --gcc-toolchain=$SYSROOT/usr" | ||
| export CXX="clang++ --sysroot=$SYSROOT --gcc-toolchain=$SYSROOT/usr" | ||
| export AR=llvm-ar | ||
| export RANLIB=llvm-ranlib | ||
| export LD=ld.lld | ||
|
|
||
| ./gradlew :dexkit:cmakeBuild --console=plain | ||
| ``` | ||
|
|
||
| ## Ubuntu 18.04 target | ||
|
|
||
| Ubuntu 18.04 has an older runtime, but it can use the GCC 10 C++ headers | ||
| for C++20 `std::span` and `std::string_view::starts_with` / | ||
| `std::string_view::ends_with`. | ||
|
|
||
| ```bash | ||
| sudo env UBUNTU_CODENAME=bionic \ | ||
| bash build-support/linux-sysroot/build-linux-sysroot.sh \ | ||
| .dexkit-sysroot/ubuntu-18.04-x86_64 | ||
|
|
||
| bash build-support/linux-sysroot/fetch-libstdcxx-headers.sh \ | ||
| .dexkit-sysroot/gcc10-headers | ||
|
|
||
| SYSROOT="$PWD/.dexkit-sysroot/ubuntu-18.04-x86_64" | ||
| GCC10_HEADERS="$PWD/.dexkit-sysroot/gcc10-headers/usr/include" | ||
| COMPAT_HEADER="$PWD/.dexkit-sysroot/compat/glibc-libstdcxx10-compat.h" | ||
|
|
||
| mkdir -p "$(dirname "$COMPAT_HEADER")" | ||
| cp build-support/linux-sysroot/glibc-libstdcxx10-compat.h "$COMPAT_HEADER" | ||
|
|
||
| export CC="clang --sysroot=$SYSROOT --gcc-toolchain=$SYSROOT/usr" | ||
| export CXX="clang++ --sysroot=$SYSROOT --gcc-toolchain=$SYSROOT/usr" | ||
| export AR=llvm-ar | ||
| export RANLIB=llvm-ranlib | ||
| export LD=ld.lld | ||
| export CFLAGS= | ||
| export CXXFLAGS="-nostdinc++ -isystem $GCC10_HEADERS/c++/10 -isystem $GCC10_HEADERS/x86_64-linux-gnu/c++/10 -include $COMPAT_HEADER" | ||
| export LDFLAGS="-Wl,--no-as-needed -lpthread" | ||
|
|
||
| ./gradlew :dexkit:cmakeBuild --console=plain | ||
| ``` | ||
|
|
||
| `glibc-libstdcxx10-compat.h` undefines libstdc++ feature macros for pthread | ||
| clock APIs that are unavailable in the older glibc target. | ||
|
|
||
| `-lpthread` is needed for pre-2.34 glibc targets such as Ubuntu 18.04 because | ||
| pthread is still provided by a separate `libpthread.so.0` there. `--no-as-needed` | ||
| keeps `libpthread.so.0` in the dynamic dependencies even if the linker only sees | ||
| pthread usage indirectly through libstdc++. | ||
|
|
||
| `fetch-libstdcxx-headers.sh` downloads `libstdc++-10-dev` by parsing Ubuntu | ||
| `Packages.xz` indexes. It defaults to the focal repositories because GCC 10 is | ||
| the distro compiler there. | ||
|
|
||
| ## Ubuntu 16.04 target | ||
|
|
||
| Ubuntu 16.04 is the most constrained target. It uses the xenial GCC 5 runtime, | ||
| GCC 10 C++ headers for C++20 library declarations, and wrapper headers for | ||
| `<thread>` and `<future>` so thread construction uses the GCC 5 `_Impl_base` | ||
| ABI. Exceptions are disabled to avoid depending on newer exception ABI symbols. | ||
|
|
||
| ```bash | ||
| sudo env UBUNTU_CODENAME=xenial \ | ||
| bash build-support/linux-sysroot/build-linux-sysroot.sh \ | ||
| .dexkit-sysroot/ubuntu-16.04-x86_64 | ||
|
|
||
| bash build-support/linux-sysroot/fetch-libstdcxx-headers.sh \ | ||
| .dexkit-sysroot/gcc10-headers | ||
|
|
||
| SYSROOT="$PWD/.dexkit-sysroot/ubuntu-16.04-x86_64" | ||
| GCC10_HEADERS="$PWD/.dexkit-sysroot/gcc10-headers/usr/include" | ||
| COMPAT_DIR="$PWD/.dexkit-sysroot/compat" | ||
| COMPAT_HEADER="$COMPAT_DIR/glibc-libstdcxx10-compat.h" | ||
| WRAPPER_DIR="$COMPAT_DIR/gcc5-thread-wrapper" | ||
|
|
||
| mkdir -p "$WRAPPER_DIR" | ||
| cp build-support/linux-sysroot/glibc-libstdcxx10-compat.h "$COMPAT_HEADER" | ||
| sed "s|@TARGET_SYSROOT@|$SYSROOT|g" \ | ||
| build-support/linux-sysroot/gcc5-thread-wrapper/thread.in \ | ||
| > "$WRAPPER_DIR/thread" | ||
| sed "s|@TARGET_SYSROOT@|$SYSROOT|g" \ | ||
| build-support/linux-sysroot/gcc5-thread-wrapper/future.in \ | ||
| > "$WRAPPER_DIR/future" | ||
|
|
||
| export CC="clang --sysroot=$SYSROOT --gcc-toolchain=$SYSROOT/usr" | ||
| export CXX="clang++ --sysroot=$SYSROOT --gcc-toolchain=$SYSROOT/usr" | ||
| export AR=llvm-ar | ||
| export RANLIB=llvm-ranlib | ||
| export LD=ld.lld | ||
| export CFLAGS= | ||
| export CXXFLAGS="-fno-exceptions -nostdinc++ -isystem $WRAPPER_DIR -isystem $GCC10_HEADERS/c++/10 -isystem $GCC10_HEADERS/x86_64-linux-gnu/c++/10 -include $COMPAT_HEADER" | ||
| export LDFLAGS="-Wl,--no-as-needed -lpthread" | ||
|
|
||
| ./gradlew :dexkit:cmakeBuild --console=plain | ||
| ``` | ||
|
|
||
| Compared with 18.04, the 16.04 target additionally needs the GCC 5 | ||
| `<thread>`/`<future>` wrappers and `-fno-exceptions`. These are only for the | ||
| GCC 5 libstdc++ runtime; they can be removed if the minimum target is raised to | ||
| 18.04 or newer. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github ci 不应该假设主组与用户一致, 考虑 "$(id -u):$(id -g)"