1DOLLY 72TOOLCHAIN rust-build3REQUIRES HOST runtime@04REQUIRES HOST display@05REQUIRES HOST input@06REQUIRES HOST dso@07REQUIRES HOST http@08REQUIRES HOST threads@0910# Rust as Dolly builds it: rustc, its standard library and Cargo, compiled11# here from their pinned sources. The seed builds the first rustc; that one12# builds the rustc kept. Every Rust program in the catalog is built by this13# image's toolchain.14FROM /v0.1.5/demos/rust/Dollyfile-rust-sdk 2b1c52115a60e5aaecda6fc2c945e24eaed3fb1896663e2b1f1e3dcf1394c4e115COPY /v0.1.5/demos/rust/Dollyfile-rust-llvm 9745780ebc082ac4e3342491955721bcb4e64539eb555028faa88476d94d6cae /opt/rust-llvm /opt/rust-llvm16# patch, for the compiler's patch below.17INSTALL /v0.1.5/Dollyfile-git 36cca7d2496d2af13507047e0ede8d2122334c1888dfec31c86d28a3e036ea1618# cmp, for the check that the second generation rebuilds the same library.19INSTALL /v0.1.5/Dollyfile-posix a98de8b50ce0a29e867194e9fe9c44a54c0ea48ccf25a0f1353431daf827cf9e20REQUIRES TOOL cargo21REQUIRES TOOL rustc22REQUIRES TOOL cc23REQUIRES TOOL cmp24REQUIRES TOOL patch25REQUIRES TOOL gzip26REQUIRES TOOL tar27REQUIRES TOOL cp28REQUIRES TOOL mkdir29REQUIRES TOOL ln30REQUIRES TOOL rm3132# rustc's and std's source as the seed's build prepared it, their locked33# crates as Cargo's directory source, and the build's settings in34# /tmp/rustc/.cargo/config.toml.35SOURCE /v0.1.5/dist/static/rust/rustc.tar.gz ca0d133f3ac7ce71572cbf61e4da7e40b9f574937d163f1df2a0d7c5cd2e5198 /tmp/rustc.tar.gz36SLOP gzip -dc /tmp/rustc.tar.gz | tar -xf - -C /37SLOP rm /tmp/rustc.tar.gz38# rustdoc builds its sessions from the default options, whose sysroot the39# static compiler finds only by its symlinked name, as rustdoc-real is: the40# lookup checked lib/rustlib against the working directory, not that sysroot.41SOURCE /v0.1.5/dist/static/rust/rustc-sysroot.patch 1446ec39a26318f5caa6ec71f71490225ca26b5b8313074f14ff812f92e6cf7f /tmp/rustc/sysroot.patch42SLOP patch -p1 -d /tmp/rustc/source -i /tmp/rustc/sysroot.patch43# The target as Dolly defines it now (panics unwind). The seed's library was44# built for the seed's definition, which stays the host's until a library for45# this one replaces it: a crate built for one cannot link the other's.46SOURCE /v0.1.5/dist/static/rust/wasm64-emscripten-probe.json 90972fb95b4f3f9abdc5a4483d284afc349095f504fa5febf3612c69cd93d053 /tmp/rustc/spec/wasm64-emscripten-probe.json4748# One generation: the compiler, built by the rustc in /opt/rust-sdk against the49# standard library there, replaces that rustc. It is linked as a host of50# procedural-macro libraries, with room for its data.51FILE /tmp/rustc/compiler.slop52    cd /tmp/rustc/source53    RUSTC_BOOTSTRAP=1 cargo rustc -j 4 --offline -p rustc-main --bin rustc-main --features llvm --target-dir /tmp/rustc/target -- -C link-arg=-rdynamic -C link-arg=-Wl,--initial-memory=3355443254    cp /tmp/rustc/target/debug/rustc-main /opt/rust-sdk/bin/rustc-real55# The standard library for that target by the rustc in /opt/rust-sdk, left in56# /tmp/rustc/sdk-target, with libtest for cargo test; its build scripts run on57# the host. Cargo's build-std reads the source below the sysroot and builds it58# for a crate. The compiler aborts, as its first generation must with the59# seed's library; the library unwinds.60FILE /tmp/rustc/std.slop61    cd /tmp/rustc/sdk62    rm -rf /tmp/rustc/sdk-target63    RUSTC_BOOTSTRAP=1 RUSTC_WRAPPER=/tmp/rustc/std-rustc RUSTFLAGS="-C relocation-model=pic -C embed-bitcode=yes" cargo build -j 4 --offline --lib --target /tmp/rustc/spec/wasm64-emscripten-probe.json -Z json-target-spec -Z build-std=std,panic_abort,proc_macro,test --target-dir /tmp/rustc/sdk-target --config 'profile.dev.panic="unwind"'64    rm /tmp/rustc/sdk-target/wasm64-emscripten-probe/debug/deps/libdolly_rust_sdk-*65# As in Rust's own build, the library unwinds and its abort runtime aborts, so66# a program of either strategy links them.67FILE /tmp/rustc/std-rustc68    #!/bin/slop69    case " $* " in70      *" --crate-name panic_abort "*) exec "$@" -C panic=abort ;;71    esac72    exec "$@"73FILE /tmp/rustc/sdk/Cargo.toml74    [package]75    name = "dolly-rust-sdk"76    version = "0.0.0"77    edition = "2024"78    [workspace]79FILE /tmp/rustc/sdk/src/lib.rs80    // Built for its dependency: the standard library.81# rustc and rustdoc are one executable, as natively both link one82# librustc_driver; rustdoc names the compiler's crates itself (rustc_private),83# so it builds against the libraries a generation leaves in /tmp/rustc/target.84FILE /tmp/rustc/driver.slop85    cd /tmp/rustc/driver86    RUSTC_BOOTSTRAP=1 RUSTFLAGS="-C relocation-model=pic -L /tmp/rustc/target/debug/deps" DOC_RUST_LANG_ORG_CHANNEL=https://doc.rust-lang.org/nightly cargo rustc -j 4 --offline --target-dir /tmp/rustc/driver-target -- -C link-arg=-rdynamic -C link-arg=-Wl,--initial-memory=3355443287    cp /tmp/rustc/driver-target/debug/dolly-rustc /opt/rust-sdk/bin/rustc-real88    rm -rf /tmp/rustc/driver-target89FILE /tmp/rustc/driver/Cargo.toml90    [package]91    name = "dolly-rustc"92    version = "0.0.0"93    edition = "2024"94    [dependencies]95    rustdoc = { path = "../source/src/librustdoc" }96    [workspace]97FILE /tmp/rustc/driver/src/main.rs98    // rustc, or rustdoc when it runs as rustdoc-real.99    #![feature(rustc_private)]100    extern crate rustc_driver;101    use std::ffi::OsStr;102    use std::path::Path;103    use std::process::ExitCode;104    fn main() -> ExitCode {105        let name = std::env::args_os().next().unwrap_or_default();106        if Path::new(&name).file_name() == Some(OsStr::new("rustdoc-real")) {107            rustdoc::main()108        } else {109            rustc_driver::main()110        }111    }112SLOP mkdir -p /opt/rust-sdk/lib/rustlib/src/rust113SLOP cp -R /tmp/rustc/source/library /opt/rust-sdk/lib/rustlib/src/rust/library114115# The first generation is the seed's work and links the seed's standard116# library. Its own standard library replaces the seed's, and the target's117# definition with it.118SLOP slop -e /tmp/rustc/compiler.slop119SLOP rm -rf /tmp/rustc/target120SLOP slop -e /tmp/rustc/std.slop121SLOP slop -c 'rm /opt/rust-sdk/lib/rustlib/wasm64-emscripten-probe/lib/*.rlib'122SLOP slop -c 'cp /tmp/rustc/sdk-target/wasm64-emscripten-probe/debug/deps/*.rlib /opt/rust-sdk/lib/rustlib/wasm64-emscripten-probe/lib'123SLOP cp /tmp/rustc/spec/wasm64-emscripten-probe.json /opt/rust-sdk/wasm64-emscripten-probe.json124SLOP cp /tmp/rustc/spec/wasm64-emscripten-probe.json /opt/rust-sdk/lib/rustlib/wasm64-emscripten-probe/target.json125# The second generation is built by the first from the same source and holds126# nothing of the seed: it is the rustc this image keeps, with rustdoc. The127# standard library it builds must be, byte for byte, the one installed.128SLOP slop -e /tmp/rustc/compiler.slop129SLOP slop -e /tmp/rustc/driver.slop130SLOP ln -s rustc-real /opt/rust-sdk/bin/rustdoc-real131SLOP ln -s rustc /opt/rust-sdk/bin/rustdoc132SLOP rm -rf /tmp/rustc/target133SLOP slop -e /tmp/rustc/std.slop134SLOP CWD /tmp/rustc/sdk-target/wasm64-emscripten-probe/debug/deps slop -e -c 'for library in *.rlib; do cmp "$library" "/opt/rust-sdk/lib/rustlib/wasm64-emscripten-probe/lib/$library"; done'135SLOP rm -rf /tmp/rustc /opt/rust-llvm /opt/rust-sdk/lib/rustlib/src136137# Cargo, by the kept compiler and library; the seed's Cargo drives its last build.138SOURCE /v0.1.5/dist/static/rust/cargo.tar.gz a1cfcffcac95319a5d6d161ffe6e2b71bba8465943ddd933fb31c795f83ad197 /tmp/cargo.tar.gz139SLOP gzip -dc /tmp/cargo.tar.gz | tar -xf - -C /140SLOP rm /tmp/cargo.tar.gz141SLOP CWD /tmp/cargo/source cargo build -j 4 --offline --bin cargo --target-dir /tmp/cargo/build142SLOP cp /tmp/cargo/build/debug/cargo /usr/bin/cargo143SLOP mkdir -p /usr/share/licenses/cargo /usr/share/dolly/builds144SLOP cp /tmp/cargo/source/LICENSE-MIT /usr/share/licenses/cargo/LICENSE-MIT145SLOP cp /tmp/cargo/source/LICENSE-APACHE /usr/share/licenses/cargo/LICENSE-APACHE146SLOP cp /tmp/cargo/source/LICENSE-THIRD-PARTY /usr/share/licenses/cargo/LICENSE-THIRD-PARTY147SLOP cp /tmp/cargo/vendor/libgit2-sys-0.18.5+1.9.4/libgit2/COPYING /usr/share/licenses/cargo/libgit2-COPYING148SLOP cp /tmp/cargo/source/Cargo.lock /usr/share/dolly/builds/cargo.lock149SLOP rm -rf /tmp/cargo150151# The SDK's members are this recipe's now, not the seed's.152EXPORTS FOLDER rust-sdk /opt/rust-sdk153EXPORTS FOLDER rust-licenses /usr/share/licenses/rust154EXPORTS FOLDER cargo-licenses /usr/share/licenses/cargo155FILE /usr/share/dolly/builds/cargo.lock156SLOP rustc --version --verbose157SLOP rustdoc --version158SLOP cargo --version159160# The built toolchain builds and runs a program that uses a procedural macro.161FILE /tmp/rust-check/Cargo.toml162    [workspace]163    members = ["twice", "check"]164    resolver = "3"165FILE /tmp/rust-check/twice/Cargo.toml166    [package]167    name = "twice"168    version = "0.1.0"169    edition = "2024"170    [lib]171    proc-macro = true172FILE /tmp/rust-check/twice/src/lib.rs173    use proc_macro::TokenStream;174    #[proc_macro]175    pub fn twice(input: TokenStream) -> TokenStream {176        format!("({0}) + ({0})", input).parse().unwrap()177    }178FILE /tmp/rust-check/check/Cargo.toml179    [package]180    name = "check"181    version = "0.1.0"182    edition = "2024"183    [dependencies]184    twice = { path = "../twice" }185FILE /tmp/rust-check/check/src/main.rs186    fn main() { println!("built by cargo: {}", twice::twice!(21)); }187SLOP CWD /tmp/rust-check cargo build --offline188SLOP /tmp/rust-check/target/debug/check189SLOP rm -rf /tmp/rust-check190191ENTRY /bin/foreground -i /bin/slop192