Skip to content

Commit 95d7fbc

Browse files
committed
Put src and output into its own directory
1 parent 69b64d4 commit 95d7fbc

File tree

7 files changed

+73
-70
lines changed

7 files changed

+73
-70
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
sudo apt-get -y install cmake ninja-build libzstd-dev binutils-dev
2828
wget https://apt.llvm.org/llvm.sh
2929
chmod +x llvm.sh
30-
sudo ./llvm.sh 18
30+
sudo ./llvm.sh 19
3131
rm llvm.sh
3232
./build.sh
3333
@@ -101,9 +101,9 @@ jobs:
101101
- name: Build toolchain
102102
run: |
103103
brew reinstall ninja zstd binutils gpatch
104-
./build.sh clone build
104+
./build.sh clone build collect
105105
mkdir tmp
106-
tar c out | xz --x86 --lzma2 > tmp/out.x64.tar.xz
106+
tar c out/collect | xz --x86 --lzma2 > tmp/out.x64.tar.xz
107107
108108
- name: Upload build artifact
109109
uses: actions/upload-artifact@v4
@@ -129,9 +129,9 @@ jobs:
129129
- name: Build toolchain
130130
run: |
131131
brew reinstall ninja zstd binutils gpatch
132-
./build.sh clone build
132+
./build.sh clone build collect
133133
mkdir tmp
134-
tar c out | xz > tmp/out.arm64.tar.xz
134+
tar c out/collect | xz > tmp/out.arm64.tar.xz
135135
136136
- name: Upload build artifact
137137
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
/rust
1+
/src
22
/out
3-
/rust-out
43
/dist
54
/tmp
6-
/ondk-*
75
/*.zip
8-
/llvm-project
9-
/llvm_android
10-
/toolchain-utils

build-windows.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,24 @@ build() {
3737
set_llvm_cfg LLVM_ENABLE_LIBCXX TRUE
3838
# MinGW libstdc++ is incompatible with clang when LTO is enabled, we have to use libc++
3939
set_build_cfg llvm.use-libcxx true
40-
set_build_cfg rust.use-lld self-contained
40+
set_build_cfg rust.use-lld true
4141
set_build_cfg dist.include-mingw-linker true
4242

43-
cd rust
43+
cd src/rust
4444
eval python ./x.py --config ../config.toml --build $TRIPLE $(print_build_cfg) install
45-
cd ../
45+
cd ../../
4646
}
4747

4848
collect() {
49-
cp -af rust-out out
50-
cd out
49+
cp -af out/rust out/collect
50+
cd out/collect
51+
52+
local RUST_BUILD=../../src/rust/build
5153

5254
find . -name '*.old' -delete
53-
cp -af ../rust/build/$TRIPLE/llvm/bin llvm-bin || true
54-
cp -an ../rust/build/$TRIPLE/llvm/bin/. llvm-bin/.
55-
cp -af ../rust/build/tmp/dist/lib/rustlib/. lib/rustlib/.
55+
cp -af $RUST_BUILD/$TRIPLE/llvm/bin llvm-bin || true
56+
cp -an $RUST_BUILD/$TRIPLE/llvm/bin/. llvm-bin/.
57+
cp -af $RUST_BUILD/tmp/dist/lib/rustlib/. lib/rustlib/.
5658

5759
local MINGW_DIR=lib/rustlib/$TRIPLE/bin/self-contained
5860

@@ -62,8 +64,8 @@ collect() {
6264
cp_sys_dlls $MINGW_DIR/ld.exe
6365
cp_sys_dlls $MINGW_DIR/x86_64-w64-mingw32-gcc.exe
6466

65-
strip_exe ../rust/build/$TRIPLE/llvm/bin/llvm-strip.exe
66-
cd ..
67+
strip_exe $RUST_BUILD/$TRIPLE/llvm/bin/llvm-strip.exe
68+
cd ../../
6769
}
6870

6971
cp_sys_dlls() {
@@ -75,10 +77,11 @@ cp_sys_dlls() {
7577

7678
ndk() {
7779
dl_ndk
80+
cd out
7881

7982
# Copy the whole output folder into ndk
80-
cp -af out ndk/toolchains/rust || true
81-
cp -an out/. ndk/toolchains/rust/.
83+
cp -af collect ndk/toolchains/rust || true
84+
cp -an collect/. ndk/toolchains/rust/.
8285

8386
cd ndk/toolchains
8487

@@ -92,7 +95,7 @@ ndk() {
9295
update_dir rust/llvm-bin $LLVM_DIR/bin
9396
rm -rf rust/llvm-bin
9497

95-
cd ../..
98+
cd ../../../
9699
}
97100

98101
export PATH='/c/Program Files/Git/cmd':$PATH

build.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,35 @@ build() {
4444
else
4545
set_llvm_cfg LLVM_BINUTILS_INCDIR /usr/include
4646
set_build_cfg llvm.static-libstdcpp true
47-
set_build_cfg rust.use-lld self-contained
47+
set_build_cfg rust.use-lld true
4848
fi
4949

5050
set_llvm_cfg LLVM_ENABLE_PLUGINS FORCE_ON
5151

52-
cd rust
53-
eval python3 ./x.py --config ../config.toml --host $TRIPLE $(print_build_cfg) install
54-
cd ../
52+
cd src/rust
53+
eval python3 ./x.py --config ../../config.toml --host $TRIPLE $(print_build_cfg) install
54+
cd ../../
5555
}
5656

5757
collect() {
58-
cp -af rust-out out
59-
cd out
58+
cp -af out/rust out/collect
59+
cd out/collect
60+
61+
local RUST_BUILD=../../src/rust/build
6062

6163
find . -name '*.old' -delete
62-
cp -af ../rust/build/$TRIPLE/llvm/bin llvm-bin
63-
find ../rust/build/$TRIPLE/llvm/lib -name "*.${DYN_EXT}*" -exec cp -an {} lib \;
64+
cp -af $RUST_BUILD/$TRIPLE/llvm/bin llvm-bin
65+
find $RUST_BUILD/$TRIPLE/llvm/lib -name "*.${DYN_EXT}*" -exec cp -an {} lib \;
6466
strip_exe llvm-bin/llvm-strip
65-
cd ..
67+
cd ../../
6668
}
6769

6870
ndk() {
6971
dl_ndk
72+
cd out
7073

7174
# Copy the whole output folder into ndk
72-
cp -af out ndk/toolchains/rust
75+
cp -af collect ndk/toolchains/rust
7376

7477
cd ndk/toolchains
7578

@@ -81,7 +84,7 @@ ndk() {
8184
cd $LLVM_DIR/lib
8285
ln -sf ../../../../rust/lib/*.$DYN_EXT* .
8386

84-
cd ../../../../../../
87+
cd ../../../../../../../
8588
}
8689

8790

common.sh

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@ strip_exe() {
4747
# url sha
4848
git_clone_sha() {
4949
local dir=${1##*/}
50-
mkdir "$dir"
51-
cd "$dir"
50+
echo "Cloning into 'src/$dir'..."
51+
mkdir -p "src/$dir"
52+
cd "src/$dir"
5253
git init -q
5354
git remote add origin $1
5455
git fetch --depth 1 origin $2
5556
git reset --hard FETCH_HEAD
56-
cd ../
57+
cd ../../
5758
}
5859

5960
git_clone_branch() {
60-
git clone --single-branch --depth 1 --branch $2 $1
61+
local dir=${1##*/}
62+
git clone --single-branch --depth 1 --branch $2 $1 src/$dir
6163
}
6264

6365
skip_submodule() {
@@ -66,24 +68,24 @@ skip_submodule() {
6668
}
6769

6870
clone_llvm() {
69-
rm -rf llvm-project llvm_android toolchain-utils
71+
rm -rf src/llvm-project src/llvm_android src/toolchain-utils
7072

7173
git_clone_sha https://android.googlesource.com/toolchain/llvm-project $LLVM_VERSION
7274
git_clone_sha https://android.googlesource.com/toolchain/llvm_android $LLVM_ANDROID_VERSION
7375
git_clone_sha https://android.googlesource.com/platform/external/toolchain-utils $TOOLCHAIN_UTILS_VERSION
7476

7577
# Patch the LLVM source code
76-
$PYTHON_CMD toolchain-utils/llvm_tools/patch_manager.py \
78+
$PYTHON_CMD src/toolchain-utils/llvm_tools/patch_manager.py \
7779
--svn_version $LLVM_SVN \
78-
--patch_metadata_file llvm_android/patches/PATCHES.json \
79-
--src_path llvm-project
80+
--patch_metadata_file src/llvm_android/patches/PATCHES.json \
81+
--src_path src/llvm-project
8082
}
8183

8284
clone_rust() {
83-
rm -rf rust
85+
rm -rf src/rust
8486

8587
git_clone_branch https://github.com/rust-lang/rust $RUST_VERSION
86-
cd rust
88+
cd src/rust
8789

8890
# Skip unused submodules
8991
skip_submodule llvm-project
@@ -95,15 +97,15 @@ clone_rust() {
9597
git submodule update --init --depth=1
9698

9799
# Apply patches
98-
for p in ../patches/*.patch; do
100+
for p in ../../patches/*.patch; do
99101
patch -p1 < $p
100102
done
101103

102104
# Link NDK LLVM into Rust's source
103105
rm -rf src/llvm-project
104106
ln -s ../../llvm-project src/llvm-project
105107

106-
cd ../
108+
cd ../../
107109
}
108110

109111
update_dir() {
@@ -135,14 +137,16 @@ dl_ndk() {
135137
[ -f $NDK_ZIP ] || curl -O -L "https://dl.google.com/android/repository/$NDK_ZIP"
136138
rm -rf $NDK_EXTRACT
137139
unzip -q $NDK_ZIP
138-
mv $NDK_EXTRACT ndk
139-
echo $OUTPUT_VERSION > ndk/ONDK_VERSION
140+
mv $NDK_EXTRACT out/ndk
141+
echo $OUTPUT_VERSION > out/ndk/ONDK_VERSION
140142
}
141143

142144
dist() {
145+
cd out
143146
mv ndk "ondk-${OUTPUT_VERSION}"
144-
mkdir dist
145-
tar c "ondk-${OUTPUT_VERSION}" | xz --x86 --lzma2 > "dist/ondk-${OUTPUT_VERSION}-${OS}.tar.xz"
147+
mkdir ../dist
148+
tar c "ondk-${OUTPUT_VERSION}" | xz --x86 --lzma2 > "../dist/ondk-${OUTPUT_VERSION}-${OS}.tar.xz"
149+
cd ../
146150
}
147151

148152
run_cmd() {
@@ -158,27 +162,25 @@ run_cmd() {
158162
clone_rust
159163
;;
160164
build)
161-
rm -rf rust-out
165+
rm -rf out/rust
162166
# Set common LLVM configs
163167
set_llvm_cfg LLVM_VERSION_SUFFIX
164168
build
165169
;;
166170
collect)
167-
rm -rf out
171+
rm -rf out/collect
168172
collect
169173
;;
170174
ndk)
171-
rm -rf ndk
175+
rm -rf out/ndk
172176
ndk
173177
;;
174178
dist)
175-
rm -rf dist ondk-*
179+
rm -rf dist out/ondk-*
176180
dist
177181
;;
178182
clean)
179-
rm -rf rust llvm-project llvm_android toolchain-utils \
180-
out out.arm out.x86 ndk tmp mingw64 \
181-
android-ndk-*.zip ondk-* dist mingw.7z
183+
rm -rf src out dist tmp android-ndk-*.zip
182184
;;
183185
*)
184186
echo "Unknown action \"$1\""

config.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tools = [
2626
cargo-native-static = true
2727

2828
[install]
29-
prefix = "../rust-out"
29+
prefix = "../../out/rust"
3030
sysconfdir = "etc"
3131

3232
[rust]
@@ -38,9 +38,9 @@ codegen-units = 1
3838

3939
[target.x86_64-unknown-linux-gnu]
4040
llvm-has-rust-patches = false
41-
cc = "clang-18"
42-
cxx = "clang++-18"
43-
linker = "clang-18"
41+
cc = "clang-19"
42+
cxx = "clang++-19"
43+
linker = "clang-19"
4444

4545
[target.aarch64-apple-darwin]
4646
llvm-has-rust-patches = false

dist-macos.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#!/usr/bin/env bash
22

3-
# Copyright 2022-2024 Google LLC.
3+
# Copyright 2022-2025 Google LLC.
44
# SPDX-License-Identifier: Apache-2.0
55

66
# This script is for generating universal binaries
77

88
set -e
99

1010
xz -d < tmp/out.x64.tar.xz | tar x
11-
mv out out.x64
11+
mv out/collect out/collect.x64
1212
xz -d < tmp/out.arm64.tar.xz | tar x
13-
mv out out.arm64
13+
mv out/collect out/collect.arm64
1414

15-
cp -af out.x64 out
16-
cp -an out.arm64/. out/. || true
15+
cp -af out/collect.x64 out/collect
16+
cp -an out/collect.arm64/. out/collect/. || true
1717

1818
# Merge all Mach-O files as universal binary and adhoc codesign
19-
find out -type f -exec sh -c "file {} | grep -q Mach-O" \; -print0 | \
19+
find out/collect -type f -exec sh -c "file {} | grep -q Mach-O" \; -print0 | \
2020
while IFS= read -r -d '' o; do
21-
a="${o/out/out.x64}"
22-
b="${o/out/out.arm64}"
21+
a="${o/collect/collect.x64}"
22+
b="${o/collect/collect.arm64}"
2323
if [ -f "$a" -a -f "$b" ]; then
2424
lipo -create -output "$o" "$a" "$b"
2525
fi

0 commit comments

Comments
 (0)