-
Notifications
You must be signed in to change notification settings - Fork 36
/
build.sh
executable file
·89 lines (71 loc) · 2.11 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
# Copyright 2022-2024 Google LLC.
# SPDX-License-Identifier: Apache-2.0
. common.sh
OS=$(uname | tr '[:upper:]' '[:lower:]')
NATIVE_ARCH=$(uname -m)
if [ $NATIVE_ARCH = "arm64" ]; then
# Apple calls aarch64 arm64
NATIVE_ARCH='aarch64'
fi
if [ -z $ARCH ]; then
# Build the native architecture by default
ARCH=$NATIVE_ARCH
fi
if [ $OS = "darwin" ]; then
NDK_DIRNAME='darwin-x86_64'
TRIPLE="${ARCH}-apple-darwin"
NATIVE_TRIPLE="${NATIVE_ARCH}-apple-darwin"
DYN_EXT='dylib'
EXE_FMT='Mach-O'
# Always use GNU patch
export PATH="$(brew --prefix)/opt/gpatch/bin:$PATH"
else
NDK_DIRNAME='linux-x86_64'
TRIPLE="${ARCH}-unknown-linux-gnu"
NATIVE_TRIPLE="${NATIVE_ARCH}-unknown-linux-gnu"
DYN_EXT='so'
EXE_FMT='ELF'
fi
build() {
if [ $OS = "darwin" ]; then
export MACOSX_DEPLOYMENT_TARGET=11.0
# Manually set page size if cross compilation is required (arm64 require 16k page)
# export JEMALLOC_SYS_WITH_LG_PAGE=14
set_llvm_cfg LLVM_BINUTILS_INCDIR $(brew --prefix)/opt/binutils/include
set_build_cfg rust.jemalloc true
else
set_llvm_cfg LLVM_BINUTILS_INCDIR /usr/include
set_build_cfg llvm.static-libstdcpp true
set_build_cfg rust.use-lld self-contained
fi
set_llvm_cfg LLVM_ENABLE_PLUGINS FORCE_ON
set_build_cfg llvm.thin-lto true
set_build_cfg llvm.link-shared true
set_build_cfg rust.lto thin
cd rust
eval python3 ./x.py --config ../config.toml --host $TRIPLE $(print_build_cfg) install
cd ../
cd out
find . -name '*.old' -delete
cp -af ../rust/build/$TRIPLE/llvm/bin llvm-bin
cp -af lib/rustlib/$TRIPLE/bin/rust-lld llvm-bin/lld
ln -sf lld llvm-bin/ld
find ../rust/build/$TRIPLE/llvm/lib -name "*.${DYN_EXT}*" -exec cp -an {} lib \;
strip_exe
cd ..
}
ndk() {
dl_ndk
# Copy the whole output folder into ndk
cp -af out ndk/toolchains/rust
cd ndk/toolchains
local LLVM_DIR=llvm/prebuilt/$NDK_DIRNAME
# Replace files with those from the rust toolchain
update_dir rust/llvm-bin $LLVM_DIR/bin
rm -rf rust/llvm-bin
cd $LLVM_DIR/lib
ln -sf ../../../../rust/lib/*.$DYN_EXT* .
cd ../../../../../../
}
parse_args $@