Skip to content

Commit a3dbfae

Browse files
committed
initial multi-stage build
disable bolt for now
1 parent 129c1f3 commit a3dbfae

File tree

5 files changed

+202
-56
lines changed

5 files changed

+202
-56
lines changed

.github/workflows/build.yml

Lines changed: 113 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,123 @@ on:
44
branches:
55
- main
66
jobs:
7-
build:
7+
build-llvm-bootstrap:
8+
name: Build bootstrap LLVM
89
runs-on: ubuntu-latest
910
steps:
1011
- uses: actions/checkout@main
1112
- name: Install dependencies
12-
run: bash ci.sh deps
13-
- name: Build LLVM
14-
run: bash ci.sh llvm
13+
run: bash ci.sh do_deps
14+
- name: Build
15+
run: bash ci.sh do_bootstrap
16+
- name: Pack artifact
17+
if: always()
18+
run: bash ci.sh do_pack
19+
- uses: actions/upload-artifact@main
20+
if: always()
21+
with:
22+
name: llvm-bootstrap
23+
path: artifact.tar
24+
25+
build-llvm-instrumented:
26+
name: Build instrumented LLVM
27+
needs: build-llvm-bootstrap
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@main
31+
- uses: actions/download-artifact@main
32+
with:
33+
name: llvm-bootstrap
34+
- name: Install dependencies and unpack artifact
35+
run: bash ci.sh "do_deps && do_unpack"
36+
- name: Build
37+
run: bash ci.sh do_instrumented
38+
- name: Pack artifact
39+
if: always()
40+
run: bash ci.sh do_pack
41+
- uses: actions/upload-artifact@main
42+
if: always()
43+
with:
44+
name: llvm-instrumented
45+
path: artifact.tar
46+
47+
build-llvm-profiling:
48+
name: Profile instrumented LLVM
49+
needs: build-llvm-instrumented
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@main
53+
- uses: actions/download-artifact@main
54+
with:
55+
name: llvm-instrumented
56+
- name: Install dependencies and unpack artifact
57+
run: bash ci.sh "do_deps && do_unpack"
58+
- name: Profile
59+
run: bash ci.sh do_profiling
60+
- name: Pack artifact
61+
if: always()
62+
run: bash ci.sh do_pack
63+
- uses: actions/upload-artifact@main
64+
if: always()
65+
with:
66+
name: llvm-profiling
67+
path: artifact.tar
68+
69+
build-llvm-final:
70+
name: Build final LLVM
71+
needs: build-llvm-profiling
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@main
75+
- uses: actions/download-artifact@main
76+
with:
77+
name: llvm-profiling
78+
- name: Install dependencies and unpack artifact
79+
run: bash ci.sh "do_deps && do_unpack"
80+
- name: Build
81+
run: bash ci.sh do_final
82+
- name: Pack artifact
83+
if: always()
84+
run: bash ci.sh do_pack
85+
- uses: actions/upload-artifact@main
86+
if: always()
87+
with:
88+
name: llvm-final
89+
path: artifact.tar
90+
91+
build-llvm-dist:
92+
name: Make distribution with binutils
93+
needs: build-llvm-final
94+
runs-on: ubuntu-latest
95+
steps:
96+
- uses: actions/checkout@main
97+
- uses: actions/download-artifact@main
98+
with:
99+
name: llvm-final
100+
- name: Install dependencies and unpack artifact
101+
run: bash ci.sh "do_deps && do_unpack"
15102
- name: Build binutils
16-
run: bash ci.sh binutils
17-
- name: Build kernel
18-
run: bash ci.sh kernel
19-
- name: Fix up build
20-
run: bash ci.sh fixup
21-
- name: Make dist
22-
run: bash ci.sh dist
103+
run: bash ci.sh do_binutils
104+
- name: Add finishing touches
105+
run: bash ci.sh do_fixup
106+
- name: Make .tar.xz distribution
107+
run: bash ci.sh do_dist
108+
- uses: actions/upload-artifact@main
109+
with:
110+
name: distribution
111+
path: toolchain-dist.tar.xz
112+
- name: Generate revision
113+
run: echo "REVISION=$(bash ci.sh do_revision)" >> $GITHUB_ENV
114+
- uses: softprops/action-gh-release@master
115+
with:
116+
tag_name: ${{env.REVISION}}
117+
body_path: revision-notes.md
118+
files: toolchain-dist.tar.xz
119+
- name: Pack artifact
120+
if: always()
121+
run: bash ci.sh do_pack
23122
- uses: actions/upload-artifact@main
123+
if: always()
24124
with:
25-
path: tc-build-install.tar.xz
125+
name: llvm-dist
126+
path: artifact.tar

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.idea/
22
/build/
3+
/install/
34
/venv/
45
*.pyc

build-llvm.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from argparse import ArgumentParser, RawTextHelpFormatter
55
from pathlib import Path
66
import platform
7+
import sys
78
import textwrap
89
import time
910

@@ -408,6 +409,10 @@
408409
'''),
409410
type=str,
410411
default='ClangBuiltLinux')
412+
# Custom github-actions build stages
413+
parser.add_argument('--actions-stage',
414+
type=str,
415+
choices=['bootstrap', 'instrumented', 'profiling', 'final'])
411416
args = parser.parse_args()
412417

413418
# Start tracking time that the script takes
@@ -534,7 +539,8 @@
534539

535540
# Build bootstrap compiler if user did not request a single stage build
536541
if (use_bootstrap := not args.build_stage1_only):
537-
tc_build.utils.print_header('Building LLVM (bootstrap)')
542+
if not args.actions_stage or args.actions_stage == 'bootstrap':
543+
tc_build.utils.print_header('Building LLVM (bootstrap)')
538544

539545
bootstrap = LLVMBootstrapBuilder()
540546
bootstrap.build_targets = ['distribution']
@@ -551,8 +557,13 @@
551557
bootstrap.projects.append('compiler-rt')
552558

553559
bootstrap.check_dependencies()
554-
bootstrap.configure()
555-
bootstrap.build()
560+
if not args.actions_stage or args.actions_stage == 'bootstrap':
561+
bootstrap.configure()
562+
bootstrap.build()
563+
564+
if args.actions_stage:
565+
tc_build.utils.print_info('Building LLVM (bootstrap) done.')
566+
sys.exit(0)
556567

557568
# If the user did not specify CMAKE_C_FLAGS or CMAKE_CXX_FLAGS, add them as empty
558569
# to paste stage 2 to ensure there are no environment issues (since CFLAGS and CXXFLAGS
@@ -582,11 +593,17 @@
582593
instrumented.targets = final.targets
583594
instrumented.tools = StageTools(Path(bootstrap.folders.build, 'bin'))
584595

585-
tc_build.utils.print_header('Building LLVM (instrumented)')
586-
instrumented.configure()
587-
instrumented.build()
596+
if not args.actions_stage or args.actions_stage == 'instrumented':
597+
tc_build.utils.print_header('Building LLVM (instrumented)')
598+
instrumented.configure()
599+
instrumented.build()
600+
601+
if args.actions_stage:
602+
tc_build.utils.print_info('Building LLVM (instrumented) done.')
603+
sys.exit(0)
588604

589-
tc_build.utils.print_header('Generating PGO profiles')
605+
if not args.actions_stage or args.actions_stage == 'profiling':
606+
tc_build.utils.print_header('Generating PGO profiles')
590607
pgo_builders = []
591608
if 'llvm' in args.pgo:
592609
llvm_builder = def_llvm_builder_cls()
@@ -661,12 +678,19 @@
661678
pgo_builders.append(kernel_builder)
662679

663680
for pgo_builder in pgo_builders:
681+
if args.actions_stage and args.actions_stage != 'profiling':
682+
continue
664683
if hasattr(pgo_builder, 'configure') and callable(pgo_builder.configure):
665684
tc_build.utils.print_info('Building LLVM for profiling...')
666685
pgo_builder.configure()
667686
pgo_builder.build()
668687

669-
instrumented.generate_profdata()
688+
if not args.actions_stage or args.actions_stage == 'profiling':
689+
instrumented.generate_profdata()
690+
691+
if args.actions_stage:
692+
tc_build.utils.print_info('Generating PGO profiles done.')
693+
sys.exit(0)
670694

671695
# Final build
672696
final.build_targets = args.build_targets
@@ -717,4 +741,8 @@
717741
final.build()
718742
final.show_install_info()
719743

744+
if args.actions_stage:
745+
tc_build.utils.print_info('Building LLVM (final) done.')
746+
sys.exit(0)
747+
720748
print(f"Script duration: {tc_build.utils.get_duration(script_start)}")

ci.sh

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@ src=$base/src
66

77
set -eu
88

9-
function parse_parameters() {
10-
while (($#)); do
11-
case $1 in
12-
all | binutils | deps | kernel | llvm | fixup | dist) action=$1 ;;
13-
*) exit 33 ;;
14-
esac
15-
shift
16-
done
17-
}
18-
19-
function do_all() {
20-
do_deps
21-
do_llvm
22-
do_binutils
23-
do_kernel
24-
}
25-
269
function do_binutils() {
2710
"$base"/build-binutils.py \
2811
--install-folder "$install" \
@@ -31,9 +14,6 @@ function do_binutils() {
3114
}
3215

3316
function do_deps() {
34-
# We only run this when running on GitHub Actions
35-
[[ -z ${GITHUB_ACTIONS:-} ]] && return 0
36-
3717
sudo apt-get install -y --no-install-recommends \
3818
bc \
3919
bison \
@@ -90,24 +70,21 @@ EOF
9070
}
9171

9272
function do_llvm() {
93-
extra_args=()
94-
[[ -n ${GITHUB_ACTIONS:-} ]] && extra_args+=(--no-ccache)
95-
9673
"$base"/build-llvm.py \
97-
--assertions \
98-
--bolt \
99-
--build-targets distribution \
100-
--install-folder "$install" \
101-
--install-targets distribution \
74+
--projects clang lld \
75+
--targets AArch64 ARM X86 \
10276
--lto thin \
10377
--pgo kernel-defconfig \
104-
--projects clang lld \
78+
--build-targets distribution \
79+
--install-targets distribution \
80+
--vendor-string usertam \
81+
--install-folder "$install" \
10582
--quiet-cmake \
10683
--shallow-clone \
10784
--show-build-commands \
108-
--targets AArch64 ARM X86 \
109-
--vendor-string usertam \
110-
"${extra_args[@]}"
85+
--no-ccache \
86+
--no-update \
87+
"$@"
11188
}
11289

11390
function do_fixup() {
@@ -126,13 +103,52 @@ function do_fixup() {
126103
done
127104
}
128105

106+
function do_bootstrap() {
107+
do_llvm --actions-stage bootstrap
108+
}
109+
110+
function do_instrumented() {
111+
do_llvm --actions-stage instrumented
112+
}
113+
114+
function do_profiling() {
115+
do_llvm --actions-stage profiling
116+
}
117+
118+
function do_final() {
119+
do_llvm --actions-stage final
120+
}
121+
122+
function do_pack() {
123+
tar -cf artifact.tar \
124+
$(ls -d src build install)
125+
}
126+
127+
function do_unpack() {
128+
tar -xf artifact.tar
129+
rm -rf artifact.tar
130+
}
131+
129132
function do_dist() {
130133
tar --sort=name \
131134
--mtime='1970-01-01' \
132135
--owner=0 --group=0 --numeric-owner \
133-
-I pixz -cf tc-build-install.tar.xz \
134-
-C "$install" $(ls -A "$install")
136+
-I pixz -cf toolchain-dist.tar.xz \
137+
-C "$install" $(ls "$install")
138+
}
139+
140+
function do_revision() {
141+
hash=$(git -C src/llvm-project rev-parse HEAD | cut -c -7)
142+
date=$(date +%y%m%d)
143+
cat <<EOF > revision-notes.md
144+
Built against the main branch of [llvm-project](https://github.com/llvm/llvm-project) on commit \`$hash\`.
145+
- Projects: clang, lld
146+
- Targets: aarch64, arm, x86
147+
- Bolt: None
148+
- LTO: ThinLTO (thin)
149+
- PGO: kernel-defconfig
150+
EOF
151+
echo "r$date.$hash"
135152
}
136153

137-
parse_parameters "$@"
138-
do_"${action:=all}"
154+
eval "$@"

toolchain-dist.tar

10 KB
Binary file not shown.

0 commit comments

Comments
 (0)