Skip to content

Commit

Permalink
feat(cross): clang
Browse files Browse the repository at this point in the history
  • Loading branch information
llenotre committed May 9, 2024
1 parent 2bca9ce commit c35f9e4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 5 deletions.
7 changes: 5 additions & 2 deletions builder/src/desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ pub enum SourceInner {
branch: Option<String>,
},
/// Copy from a local path to a tarball or directory.
Local(PathBuf),
Local {
/// The local path.
path: PathBuf,
},
}

/// Description of sources files, where to find them and where to place them for building.
Expand All @@ -61,7 +64,7 @@ impl Source {
pub async fn fetch(&self, build_dir: &Path) -> Result<()> {
let dest_path = common::util::concat_paths(build_dir, &self.location);
match &self.inner {
SourceInner::Local(path) => {
SourceInner::Local { path } => {
let metadata = fs::metadata(path)?;
if metadata.is_dir() {
common::util::recursive_copy(path, &dest_path)?;
Expand Down
8 changes: 5 additions & 3 deletions cross/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ fi
# Prepare
mkdir -p toolchain/repo
PATH="$(pwd)/../target/release:$PATH"
export SYSROOT="$(pwd)/toolchain/"
export LOCAL_REPO="$(pwd)/toolchain/repo/"
export SYSROOT="toolchain/"
export LOCAL_REPO="toolchain/repo/"

# binutils
blimp-builder desc/binutils toolchain/repo/
Expand All @@ -23,4 +23,6 @@ HOST="$TARGET" blimp-builder desc/musl toolchain/repo/
unset CC LD CFLAGS LDFLAGS RUSTFLAGS
yes | blimp install musl

# TODO clang
# clang
blimp-builder desc/clang toolchain/repo/
yes | blimp install clang
73 changes: 73 additions & 0 deletions cross/desc/clang/build-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/sh

set -e

mv llvm-* llvm
mkdir {clang,libc++,compiler-rt}-build

# Build clang
cd clang-build
cmake \
../llvm/llvm \
-G Ninja \
-DLLVM_ENABLE_PROJECTS="lld;clang" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_PARALLEL_COMPILE_JOBS=$JOBS \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DLLVM_TARGETS_TO_BUILD=X86 \
-DCMAKE_INSTALL_PREFIX="$SYSROOT"
ninja -j$JOBS
ninja -j$JOBS install
cd ..

# Build libstdc++
cd ../libc++-build
cmake
../llvm
-G Ninja \
-S runtimes \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
-DLIBCXX_USE_COMPILER_RT=OFF \
-DCMAKE_C_COMPILER="$SYSROOT/bin/clang" \
-DCMAKE_CXX_COMPILER="$SYSROOT/bin/clang++" \
-DCMAKE_ASM_COMPILER_TARGET="$TARGET" \
-DCMAKE_C_COMPILER_TARGET="$TARGET" \
-DCMAKE_CXX_COMPILER_TARGET="$TARGET" \
-DCMAKE_CXX_FLAGS="-nostdlib++" \
-DCMAKE_INSTALL_PREFIX=$SYSROOT
ninja -j$JOBS cxx cxxabi unwind
ninja install-cxx install-cxxabi install-unwind
cd ..

# Build compiler-rt
cd compiler-rt-build
cmake \
../llvm/compiler-rt \
-G Ninja \
-DCMAKE_C_COMPILER="$SYSROOT/bin/clang" \
-DCMAKE_CXX_COMPILER="$SYSROOT/bin/clang++" \
-DLLVM_CONFIG_PATH="$SYSROOT/bin/llvm-config" \
-DCMAKE_ASM_COMPILER_TARGET="$TARGET" \
-DCMAKE_C_COMPILER_TARGET="$TARGET" \
-DCMAKE_CXX_COMPILER_TARGET="$TARGET" \
-DCMAKE_CXX_FLAGS="-stdlib=libc++" \
-DCOMPILER_RT_BAREMETAL_BUILD=ON \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
-DCOMPILER_RT_BUILD_PROFILE=OFF \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_BUILD_ORC=ON \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DCOMPILER_RT_BUILTINS_ENABLE_PIC=OFF \
-DCMAKE_INSTALL_PREFIX=$SYSROOT/lib/clang/13.0.1/
ninja -j$JOBS
ninja -j$JOBS install
cd ..

# Patch
ln -fsv ../../lib/clang/13.0.1/lib/linux/clang_rt.crtbegin-i386.o $SYSROOT/usr/lib/crtbegin.o
ln -fsv crtbegin.o $SYSROOT/usr/lib/crtbeginS.o
ln -fsv crtbegin.o $SYSROOT/usr/lib/crtbeginT.o
ln -fsv ../../lib/clang/13.0.1/lib/linux/clang_rt.crtend-i386.o $SYSROOT/usr/lib/crtend.o
17 changes: 17 additions & 0 deletions cross/desc/clang/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"sources": [
{
"location": "/",
"url": "https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-18.1.4.tar.gz"
}
],
"package": {
"name": "clang",
"version": "18.1.4",

"description": "The Clang project provides a language front-end and tooling infrastructure for languages in the C language family (C, C++, Objective C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project.",

"build_deps": [],
"run_deps": []
}
}

0 comments on commit c35f9e4

Please sign in to comment.