From 8d53d2f85b4fde7204a49d22ce2868fa0ef44d0e Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 28 Jan 2025 17:08:07 +0800 Subject: [PATCH] ci: build libc++abi.a for musl with -fPIC --- .github/workflows/libcxxabi.yml | 89 +++++++++++++++++++++++++++++++++ llvm-version | 1 + musl.Dockerfile | 1 - scripts/build-c++abi.mjs | 51 ++++++++++--------- 4 files changed, 118 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/libcxxabi.yml create mode 100644 llvm-version diff --git a/.github/workflows/libcxxabi.yml b/.github/workflows/libcxxabi.yml new file mode 100644 index 00000000..493f581b --- /dev/null +++ b/.github/workflows/libcxxabi.yml @@ -0,0 +1,89 @@ +name: Build libc++abi + +on: + push: + branches: + - release-libcxxabi + tags-ignore: + - '**' + +permissions: + contents: write + id-token: write + attestations: write + +jobs: + setup-llvm-version: + runs-on: ubuntu-latest + outputs: + llvm-version: ${{ steps.setup-llvm-version.outputs.llvm-version }} + steps: + - uses: actions/checkout@v4 + - name: Setup + id: setup-llvm-version + run: | + echo "llvm-version=$(cat llvm-version)" >> $GITHUB_OUTPUT + + build-musl: + runs-on: ${{ matrix.settings.runs-on }} + needs: setup-llvm-version + name: Build libc++abi for ${{ matrix.settings.arch }} Linux musl + strategy: + fail-fast: false + matrix: + settings: + - { arch: x86_64, runs-on: ubuntu-latest } + - { arch: aarch64, runs-on: ubuntu-24.04-arm } + steps: + - uses: actions/checkout@v4 + - name: Build in docker + uses: addnab/docker-run-action@v3 + with: + image: node:18-alpine + options: -v ${{ github.workspace }}:/build -w /build + run: | + apk add clang llvm wget unzip cmake ninja xz tar musl-dev python3 + node scripts/build-c++abi.mjs + - uses: actions/attest-build-provenance@v2 + with: + subject-path: | + libc++abi.a + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: libc++abi-${{ matrix.settings.arch }}.a + path: libc++abi.a + + release: + needs: + - setup-llvm-version + - build-musl + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Download x86_64 + uses: actions/download-artifact@v4 + with: + name: libc++abi-x86_64.a + path: . + - name: Rename + run: | + mv libc++abi.a libc++abi-x86_64.a + - name: Download aarch64 + uses: actions/download-artifact@v4 + with: + name: libc++abi-aarch64.a + path: . + - name: Rename + run: | + mv libc++abi.a libc++abi-aarch64.a + - name: Release + uses: softprops/action-gh-release@v2 + with: + files: | + libc++abi-x86_64.a + libc++abi-aarch64.a + name: libcxxabi-${{ needs.setup-llvm-version.outputs.llvm-version }} + tag_name: libcxxabi-${{ needs.setup-llvm-version.outputs.llvm-version }} + make_latest: false + diff --git a/llvm-version b/llvm-version new file mode 100644 index 00000000..d370346a --- /dev/null +++ b/llvm-version @@ -0,0 +1 @@ +19.1.7 diff --git a/musl.Dockerfile b/musl.Dockerfile index d4afc30d..0f349a6f 100644 --- a/musl.Dockerfile +++ b/musl.Dockerfile @@ -18,7 +18,6 @@ RUN apk add --no-cache \ libc++-dev \ libc++-static \ llvm-libunwind-static \ - libc++-dev \ tar \ xz \ ninja && \ diff --git a/scripts/build-c++abi.mjs b/scripts/build-c++abi.mjs index 49b03718..2eac854a 100644 --- a/scripts/build-c++abi.mjs +++ b/scripts/build-c++abi.mjs @@ -1,37 +1,42 @@ -import { execSync } from "node:child_process"; +import { execSync } from 'node:child_process' +import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import { join } from 'node:path' -const LLVM_VERSION = "19.1.7"; +const LLVM_VERSION = readFileSync(join(fileURLToPath(import.meta.url), '..', '..', 'llvm-version'), 'utf-8').trim() execSync(`wget https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${LLVM_VERSION}.zip`, { - stdio: "inherit", -}); + stdio: 'inherit', +}) execSync(`unzip llvmorg-${LLVM_VERSION}.zip`, { - stdio: "inherit", -}); + stdio: 'inherit', +}) execSync(`mkdir -p build`, { - stdio: "inherit", + stdio: 'inherit', cwd: `llvm-project-llvmorg-${LLVM_VERSION}`, -}); +}) -execSync(`cmake -G Ninja -S runtimes -B build -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLIBCXX_ENABLE_LOCALIZATION=OFF`, { - stdio: "inherit", - cwd: `llvm-project-llvmorg-${LLVM_VERSION}`, - env: { - ...process.env, - CXX: "clang++", - CC: "clang", - CXXFLAGS: "-fPIC", +execSync( + `cmake -G Ninja -S runtimes -B build -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLIBCXX_ENABLE_LOCALIZATION=OFF`, + { + stdio: 'inherit', + cwd: `llvm-project-llvmorg-${LLVM_VERSION}`, + env: { + ...process.env, + CXX: 'clang++', + CC: 'clang', + CXXFLAGS: '-fPIC', + }, }, -}); +) execSync(`ninja -C build cxxabi`, { - stdio: "inherit", + stdio: 'inherit', cwd: `llvm-project-llvmorg-${LLVM_VERSION}`, -}); +}) -execSync(`cp build/lib/libc++abi.a /usr/lib/libc++abi.a`, { - stdio: "inherit", - cwd: `llvm-project-llvmorg-${LLVM_VERSION}`, -}); +execSync(`cp llvm-project-llvmorg-${LLVM_VERSION}/build/lib/libc++abi.a .`, { + stdio: 'inherit', +})