Skip to content

Commit

Permalink
add new libclang package
Browse files Browse the repository at this point in the history
* add second build step to Linux
* add new packaging step that includes libclang, libcxx, and clang
  • Loading branch information
ParkMyCar committed Jan 11, 2025
1 parent 27b6ab3 commit d3a1c83
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 5 deletions.
40 changes: 36 additions & 4 deletions .github/workflows/macos-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ jobs:
echo "CLANG_TARGET=$CLANG_ARCH-apple-darwin" >> $GITHUB_ENV
CLANG_VERSION=${{ inputs.clang_version }}
CLANG_MAJOR_MINOR_VERSION=$(echo "$CLANG_VERSION" | cut -d. -f1-2)
clang_major_minor=$(echo "$CLANG_VERSION" | cut -d. -f1-2)
clang_major=$(echo "$CLANG_VERSION" | cut -d '.' -f 1)
echo "CLANG_VERSION=$CLANG_VERSION" >> $GITHUB_ENV
echo "CLANG_MAJOR_MINOR_VERSION=$CLANG_MAJOR_MINOR_VERSION" >> $GITHUB_ENV
echo "clang_version=$CLANG_VERSION" >> $GITHUB_ENV
echo "clang_major_minor=$clang_major_minor" >> $GITHUB_ENV
echo "clang_major=$clang_major" >> $GITHUB_ENV
echo "shared_extension=dylib" >> $GITHUB_ENV
echo "ZSTD_ARG=$ZSTD_ARG" >> $GITHUB_ENV
Expand Down Expand Up @@ -129,8 +132,12 @@ jobs:
cxx \
cxxabi \
unwind \
builtins \
libclang
builtins
- name: build libclang
run: |
cd llvm-project
cmake --build build --target libclang
- name: package toolchain
run: |
Expand All @@ -149,6 +156,31 @@ jobs:
cd package
tar -cf - * | zstd --ultra -22 -o "../darwin_$CLANG_ARCH.tar.zst"
- name: package libclang
run: |
mkdir package_libclang
for dir in bin lib; do
mkdir package_libclang/$dir
cat clang/"$dir"_libclang.txt | while read -r val; do
# Skip anything that starts with "linux".
if [[ "$val" == linux* && -n $val ]]; then
continue
fi
# Strip the 'mac:' prefix if it exists.
val=${val#mac:}
# Unlike Linux we build into a single directory.
build_dir="build"
# Strip the 'build:' prefix if it exists.
val=${val#build:}
eval cp -rP llvm-project/$build_dir/$dir/$val package_libclang/$dir/
done
done
cd package_libclang
tar -cf - * | zstd --ultra -22 -o ../darwin_"$CLANG_ARCH"_libclang.tar.zst
- name: Upload Toolchain Artifact
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions clang/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ COPY bin.txt bin.txt
COPY include.txt include.txt
COPY lib.txt lib.txt

COPY bin_libclang.txt bin_libclang.txt
COPY lib_libclang.txt lib_libclang.txt

COPY clang_package.sh clang_package.sh
RUN chmod +x clang_package.sh

Expand Down
5 changes: 5 additions & 0 deletions clang/bin_libclang.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build:clang
build:clang-$clang_major
build:clang-cl
build:clang-cpp
build:clang++
35 changes: 34 additions & 1 deletion clang/clang_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ esac

clang_target="$clang_arch-unknown-linux-gnu"
libs_dir="$clang_arch-linux-gnu"
clang_major_minor_version=$(echo "$clang_version" | cut -d. -f1-2)
clang_major_minor=$(echo "$clang_version" | cut -d. -f1-2)

# Configure the build.

Expand Down Expand Up @@ -121,3 +121,36 @@ cmake --build build --target \
builtins \
runtimes \
sancov

# Configure the build for libclang.

cmake -G Ninja -S llvm -B build_libclang \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="-flto=thin -pthread -fPIC -O3 -DNDEBUG $target_cpu_arg $target_arch_arg" \
-DCMAKE_CXX_FLAGS="-flto=thin -pthread -fPIC -O3 -DNDEBUG $target_cpu_arg $target_arch_arg" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION="on" \
-DLLVM_ENABLE_PROJECTS="clang" \
-DCMAKE_C_COMPILER="$c_binary" \
-DCMAKE_CXX_COMPILER="$cxx_binary" \
-DCMAKE_CXX_STANDARD=17 \
-DLLVM_STATIC_LINK_CXX_STDLIB=ON \
-DLLVM_USE_LINKER="$lld_binary" \
-DLLVM_ENABLE_LIBCXX=ON \
-DLLVM_ENABLE_LTO=Thin \
-DLLVM_ENABLE_PIC=ON \
-DLLVM_ENABLE_THREADS=ON \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_ZLIB=FORCE_ON \
-DLLVM_ENABLE_ZSTD=FORCE_ON \
-DBUILD_SHARED_LIBS=OFF \
-DLLVM_INCLUDE_UTILS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_DOCS=OFF \
-DZLIB_LIBRARY=/usr/lib/$libs_dir/libz.a \
-Dzstd_LIBRARY=/usr/lib/$libs_dir/libzstd.a

# Actually build libclang.

cmake --build build_libclang --target libclang
38 changes: 38 additions & 0 deletions clang/clang_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ esac
# These values are used in the `.txt` files that define what we package.
clang_target="$clang_arch-unknown-linux-gnu"
clang_major=$(echo "$clang_version" | cut -d '.' -f 1)
clang_major_minor=$(echo "$clang_version" | cut -d. -f1-2)
shared_extension="so"

# Package the toolchain by copying everything listed from the following files:
#
Expand Down Expand Up @@ -79,3 +81,39 @@ tar -cf - * | zstd --ultra -22 -o "../linux_$clang_arch.tar.zst"
cd ..
mkdir artifacts
mv "linux_$clang_arch.tar.zst" "artifacts/linux_$clang_arch.tar.zst"

# Package up a libclang toolchain.

mkdir package_libclang

# Linux nests the libc++ one directory deep, so let's move that up.
eval cp -rP llvm-project/build/lib/$clang_target/libc++* llvm-project/build/lib/.

for dir in bin lib; do
mkdir package_libclang/$dir
cat "$dir"_libclang.txt | while read -r val; do
# Skip anything that starts with "mac".
if [[ "$val" == mac* && -n $val ]]; then
continue
fi
# Strip the 'linux:' prefix if it exists.
val=${val#linux:}

# Determine which build artifacts to read from.
build_dir="build_libclang"
if [[ "$val" == build:* ]]; then
build_dir="build"
fi
# Strip the 'build:' prefix if it exists.
val=${val#build:}
eval cp -rP llvm-project/$build_dir/$dir/$val package_libclang/$dir/
done
done

# Compress the whole directory.

cd package_libclang
tar -cf - * | zstd --ultra -22 -o ../linux_"$clang_arch"_libclang.tar.zst

cd ..
mv linux_"$clang_arch"_libclang.tar.zst artifacts/linux_"$clang_arch"_libclang.tar.zst
8 changes: 8 additions & 0 deletions clang/lib_libclang.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
libclang.$shared_extension
build:libc++.$shared_extension
linux:libclang.$shared_extension.$clang_version
linux:libclang.$shared_extension.$clang_major_minor
linux:build:libc++.$shared_extension.1.0
linux:build:libc++.$shared_extension.1
mac:build:libc++.1.0.$shared_extension
mac:build:libc++.1.$shared_extension

0 comments on commit d3a1c83

Please sign in to comment.