Skip to content

Commit

Permalink
ci: build libc++abi.a for musl with -fPIC
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Jan 28, 2025
1 parent 0816ba5 commit 467c8bb
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 23 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/libc++abi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Build libc++abi

on:
push:
branches:
- release-libc++abi
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:
- 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:
matrix:
settings:
- { arch: x86_64, runs-on: ubuntu-latest }
- { arch: aarch64, runs-on: ubuntu-24.04-arm }
steps:
- 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:
- 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: libc++abi-${{ needs.setup-llvm-version.outputs.llvm-version }}
tag_name: libc++abi-${{ needs.setup-llvm-version.outputs.llvm-version }}
make_latest: false

1 change: 1 addition & 0 deletions llvm-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
19.1.7
1 change: 0 additions & 1 deletion musl.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ RUN apk add --no-cache \
libc++-dev \
libc++-static \
llvm-libunwind-static \
libc++-dev \
tar \
xz \
ninja && \
Expand Down
50 changes: 28 additions & 22 deletions scripts/build-c++abi.mjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
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",
execSync(`cp llvm-project-llvmorg-${LLVM_VERSION}/build/lib/libc++abi.a .`, {
stdio: 'inherit',
cwd: `llvm-project-llvmorg-${LLVM_VERSION}`,
});
})

0 comments on commit 467c8bb

Please sign in to comment.