Skip to content

Commit 9ce800d

Browse files
authored
Merge pull request #8 from maestro-os/strap
Rework bootstrapping
2 parents 5b46b4d + d5a79fa commit 9ce800d

File tree

32 files changed

+511
-297
lines changed

32 files changed

+511
-297
lines changed

Cargo.lock

Lines changed: 128 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,19 @@ blimp
8383
The general usage of the command is:
8484

8585
```sh
86-
blimp-builder <package descriptor> <output repository>
86+
blimp-builder --from <package descriptor> --to <output directory>
8787
```
8888

89-
The command builds the package according to the descriptor, then writes the result in the given output repository.
89+
The command builds the package according to the descriptor, then installs it in the given output repository (used as a system root).
9090

91-
> **Note**: the structure of package descriptors and output packages is not yet documented as they are subject to changes
91+
The `--package` flag can be used to write the resulting package into an archive instead of installing it. In which case, the output directory is considered as a repository instead of a system root.
9292

93+
> **Note**: the structure of package descriptors and output packages are not yet documented as they are unstable
9394
9495

95-
### Cross compilation
9696

97-
Cross compilation is required when building package for a system with a different target triplet than the current system.
97+
### Bootstrapping
9898

99-
Toolchain building and usage scripts are available in `cross/`, more information is available [here](cross/README.md).
99+
When building packages for a new system on a different target triplet than the current system, **bootstrapping** is required.
100+
101+
Documentation about bootstrap toolchain building is available in [here](bootstrap/README.md).

bootstrap/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sysroot/
2+
work/

bootstrap/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Bootstrapping an environment
2+
3+
Bootstrapping is the process of creating an environment which allows the cross compilation of packages.
4+
5+
6+
7+
## Overview
8+
9+
The following build steps are required for bootstrapping:
10+
11+
| Package | Host triplet | Target triplet | Notes |
12+
|---------------------------------------------|--------------|----------------|-------------------------------------------------|
13+
| **binutils** | A | B | binutils stage 1, used to link by gcc stage 1 |
14+
| **gcc** (and **libgcc**) | A | B | gcc stage 1, used to compile the next step only |
15+
| **linux headers** | n/a | n/a | required by libc |
16+
| **musl** | B | n/a | libc, used by gcc stage 2 |
17+
| **zlib** | B | n/a | zlib, used by binutils stage 2 while running |
18+
| **libstdc++** | B | n/a | used by gcc stage 2, requires libc |
19+
| **binutils** | B | B | binutils stage 2 |
20+
| **gcc** (with **libgcc** and **libstdc++**) | B | B | gcc stage 2, used to cross-compile packages |
21+
22+
> **Note**: one last compilation of gcc (stage 3) will be necessary for a final system, but it is treated as a casual package and not discussed here.
23+
24+
## Building
25+
26+
First, the `sysroot` directory must be created:
27+
```sh
28+
mkdir sysroot/
29+
```
30+
31+
Then, each package has to be built, in the order of the table above.
32+
33+
The command to use for building a package is:
34+
```sh
35+
PATH="$(pwd)/sysroot/tools:$PATH" HOST=<host-triplet> TARGET=<target-triplet> blimp-builder --from desc/<pkg>/ --to sysroot/
36+
```
37+
38+
Once this is done, the second **gcc** can be used to cross compile packages (autoconf, make, etc...) on the target.
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ cd *
66
mkdir build
77
cd build
88

9-
# Compile
9+
mkdir -p "$SYSROOT/tools/$TARGET/bin"
10+
1011
../configure \
11-
--prefix=/usr \
12-
--build="$BUILD" \
13-
--host="$HOST" \
12+
--prefix="$SYSROOT/tools" \
1413
--target="$TARGET" \
14+
--with-sysroot="$SYSROOT" \
1515
--disable-werror \
1616
--disable-nls \
1717
--enable-64-bit-bfd \
1818
--enable-gprofng=no
19-
make -j${JOBS}
2019

21-
# Install
22-
make DESTDIR=$SYSROOT install -j1
20+
make -j${JOBS}
21+
make install -j1
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
}
77
],
88
"package": {
9-
"name": "binutils",
9+
"name": "bootstrap-binutils",
1010
"version": "2.44",
1111

12-
"description": "The GNU Binutils are a collection of binary tools.",
12+
"description": "Stage 1 binutils for bootstrapping",
1313

1414
"build_deps": [],
1515
"run_deps": []
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
cd *
5+
6+
mkdir build
7+
cd build
8+
9+
../configure \
10+
--prefix="/usr" \
11+
--build="$BUILD" \
12+
--host="$TARGET" \
13+
--disable-nls \
14+
--enable-shared \
15+
--enable-gprofng=no \
16+
--disable-werror \
17+
--enable-64-bit-bfd
18+
19+
make -j${JOBS}
20+
make DESTDIR="$SYSROOT" install -j1
21+
rm -v "$SYSROOT/usr/lib/lib"{bfd,ctf,ctf-nobfd,opcodes}.{a,la}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"sources": [
3+
{
4+
"location": "/",
5+
"url": "https://ftp.gnu.org/gnu/binutils/binutils-2.44.tar.gz"
6+
}
7+
],
8+
"package": {
9+
"name": "bootstrap-binutils",
10+
"version": "2.44",
11+
12+
"description": "Stage 2 binutils for bootstrapping",
13+
14+
"build_deps": [],
15+
"run_deps": []
16+
}
17+
}

bootstrap/desc/gcc1/build-hook

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -e
4+
cd *
5+
6+
# TODO use `sources` in `package.json`
7+
./contrib/download_prerequisites
8+
9+
mkdir build
10+
cd build
11+
12+
../configure \
13+
--prefix="$SYSROOT/tools" \
14+
--target="$TARGET" \
15+
--with-sysroot="$SYSROOT" \
16+
--with-newlib \
17+
--without-headers \
18+
--enable-languages=c,c++ \
19+
--disable-hosted-libstdcxx \
20+
--disable-libatomic \
21+
--disable-libgomp \
22+
--disable-libquadmath \
23+
--disable-libsanitizer \
24+
--disable-libssp \
25+
--disable-multilib \
26+
--disable-nls \
27+
--disable-shared \
28+
--disable-threads \
29+
--disable-vtv
30+
31+
mkdir -p "$SYSROOT/usr/include"
32+
33+
make -j$JOBS all-gcc
34+
make install-gcc
35+
make -j$JOBS all-target-libgcc
36+
make install-target-libgcc

bootstrap/desc/gcc1/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"sources": [
3+
{
4+
"location": "/",
5+
"url": "https://ftp.gnu.org/gnu/gcc/gcc-15.1.0/gcc-15.1.0.tar.gz"
6+
}
7+
],
8+
"package": {
9+
"name": "bootstrap-gcc1",
10+
"version": "15.1.0",
11+
12+
"description": "Stage 1 gcc for bootstrapping",
13+
14+
"build_deps": [
15+
{
16+
"name": "bootstrap-binutils",
17+
"version": "*"
18+
}
19+
],
20+
"run_deps": []
21+
}
22+
}

0 commit comments

Comments
 (0)