-
Notifications
You must be signed in to change notification settings - Fork 1
Test statically linked clang outside of Alpine Linux #13
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
Merged
nathanchance
merged 10 commits into
ClangBuiltLinux:main
from
nathanchance:test-clang-pipeline
May 27, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
33cc658
Test statically linked clang outside of Alpine Linux
nathanchance 22c734e
ci/test-clang.sh: Use long flag for volume
nathanchance 5cc84af
ci/test-clang.sh: Split docker run command over multiple lines
nathanchance 55125a5
ci/test-clang-docker.sh: Define CC and CXX explicitly
nathanchance b8a02d2
ci/test-clang.sh: Let docker cp create bin, include, and lib directories
nathanchance 179aaa1
ci/test-clang-docker.sh: Add LD_LIBRARY_PATH test
nathanchance 5f2bbad
ci: Test statically linked clang in Arch Linux containers
nathanchance a6a0b02
github: workflows: Run 'docker push' in a separate step
nathanchance 162cc51
ci/test-clang.sh: Clarify Arch Linux comment
nathanchance 50fab28
ci/test-clang-docker.sh: Use '--sysroot' for Arch Linux
nathanchance 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
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,70 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -eu | ||
|
|
||
| if [[ ! -d /repo ]]; then | ||
| echo "[-] This script needs to be run within Docker! Use test-clang.sh instead." | ||
| exit 1 | ||
| fi | ||
|
|
||
| CC=/repo/toolchain/bin/clang | ||
| CXX=/repo/toolchain/bin/clang++ | ||
| hello_c=/repo/llvm-project/hello.c | ||
| hello_cpp=/repo/llvm-project/hello.cpp | ||
| hello_exe=/tmp/hello | ||
| host_arch=$(uname -m) | ||
|
|
||
| # Print clang information, which makes sure it can run | ||
| echo "[+] Testing 'clang --version'" | ||
| "$CC" --version | ||
|
|
||
| case "$(source /usr/lib/os-release; echo "$ID")" in | ||
|
nickdesaulniers marked this conversation as resolved.
|
||
| arch) | ||
| musl_cc_flags=(--sysroot=/usr/lib/musl) | ||
|
|
||
| echo "[+] Updating OS and installing musl" | ||
| pacman -Syyu --noconfirm musl | ||
| ;; | ||
|
|
||
| fedora) | ||
| musl_cc_flags=( | ||
| -B /usr/"$host_arch"-linux-musl/lib64 # Scrt1.o, crti.o, crtn.o | ||
| -I /usr/"$host_arch"-linux-musl/include # stdio.h | ||
| -L /usr/"$host_arch"-linux-musl/lib64 # -lc | ||
|
nickdesaulniers marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| echo "[+] Updating OS" | ||
| dnf update -qy | ||
|
|
||
| echo "[+] Installing musl" | ||
| dnf install -qy \ | ||
| musl-devel \ | ||
| musl-libc \ | ||
| musl-libc-static | ||
| ;; | ||
| esac | ||
|
|
||
| ######## | ||
| # MUSL # | ||
| ######## | ||
|
|
||
| echo "[+] Testing dynamically linking hello.c against musl" | ||
| "$CC" "${musl_cc_flags[@]}" -o "$hello_exe" "$hello_c" | ||
| "$hello_exe" | ||
|
|
||
| echo "[+] Testing statically linking hello.c against musl" | ||
| "$CC" "${musl_cc_flags[@]}" -static -o "$hello_exe" "$hello_c" | ||
| "$hello_exe" | ||
|
|
||
| echo "[+] Testing dynamically linking hello.cpp against musl ('--rpath')" | ||
| # --rpath to avoid having to pull in libc++ and libunwind from distribution | ||
| "$CXX" "${musl_cc_flags[@]}" -Wl,--rpath=/repo/toolchain/lib/"$host_arch"-alpine-linux-musl -o "$hello_exe" "$hello_cpp" | ||
| "$hello_exe" | ||
|
|
||
| echo "[+] Testing dynamically linking hello.cpp against musl ('LD_LIBRARY_PATH')" | ||
| "$CXX" "${musl_cc_flags[@]}" -o "$hello_exe" "$hello_cpp" | ||
| LD_LIBRARY_PATH=/lib:/repo/toolchain/lib/"$host_arch"-alpine-linux-musl "$hello_exe" | ||
|
|
||
| echo "[+] Testing statically linking hello.cpp against musl" | ||
| "$CXX" "${musl_cc_flags[@]}" -static -lc++abi -o "$hello_exe" "$hello_cpp" | ||
| "$hello_exe" | ||
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,37 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -eu | ||
|
|
||
| trap 'rm -fr "$toolchain"' EXIT | ||
|
|
||
| # Set up workspace | ||
| rootdir=${GITHUB_WORKSPACE:-$(dirname "$(dirname "$(realpath "$0")")")} | ||
| toolchain=$rootdir/toolchain | ||
|
|
||
| # Pull toolchain out of container | ||
| echo "[+] Downloading toolchain from container" | ||
| docker create --name llvm-project ghcr.io/clangbuiltlinux/llvm-project:stage2 | ||
| mkdir "$toolchain" | ||
| docker cp llvm-project:/usr/local/bin "$toolchain" | ||
| docker cp llvm-project:/usr/local/include "$toolchain" | ||
| docker cp llvm-project:/usr/local/lib "$toolchain" | ||
| echo "[+] Cleaning up container" | ||
| docker rm llvm-project | ||
|
nickdesaulniers marked this conversation as resolved.
|
||
|
|
||
| # Test toolchain in Docker images so that the environment is consistent, | ||
| # regardless of runners. | ||
| docker_images=( | ||
| docker.io/fedora:latest | ||
|
nathanchance marked this conversation as resolved.
|
||
| ) | ||
| # Arch Linux is an x86_64-only distribution | ||
| [[ $(uname -m) = "x86_64" ]] && docker_images+=(docker.io/archlinux:latest) | ||
| for docker_image in "${docker_images[@]}"; do | ||
| echo "[+] Updating '$docker_image'" | ||
| docker pull "$docker_image" | ||
| echo "[+] Testing clang in '$docker_image' container" | ||
| docker run \ | ||
| --rm \ | ||
| --volume "$rootdir":/repo:ro \ | ||
| "$docker_image" \ | ||
| bash /repo/ci/test-clang-docker.sh | ||
| done | ||
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.
Uh oh!
There was an error while loading. Please reload this page.