1DOLLY 82TOOLCHAIN 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 /demos/rust/Dollyfile-rust-sdk 6fa634269c5d36498bd64f41b568259af48f0d8755c2ae65095bdbcf19b1612515COPY /demos/rust/Dollyfile-rust-llvm 789ecfd73235e7de96a0c30982741ca5871d2c03cf6bd8bde4229ab9a55d7bab /opt/rust-llvm /opt/rust-llvm16# patch, for the compiler's patch below.17INSTALL /Dollyfile-git beec0dcd0aadae135004bdad2dc5ca42ae35cbf06eb67475d0c57e9185bd4f7618# cmp, for the check that the second generation rebuilds the same library.19INSTALL /Dollyfile-posix bd721815ffc3d3b9d887f57c3260749cb1db05ed2fe3f46a38b37e00ee66391b20REQUIRES 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 toolchain/prepare.sh prepared it, their locked33# crates as Cargo's directory source, and the build's settings in34# /tmp/rustc/.cargo/config.toml.35SOURCE /dist/static/rust/rustc.tar.gz 9bd9f3b84e55a5bc76f20d9c232a7bbb191bbcaaa897b00462329563f0b9b404 /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 /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 until a library for this one45# replaces it: a crate built for one cannot link the other's.46SOURCE /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 (unwinding made it 1.5 to 3 times59# slower); 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'135# The libc a crate's [patch.crates-io] takes (vendor-crates) is the library's.136SLOP rm -rf /opt/rust-sdk/src/libc137SLOP cp -R /tmp/rustc/libc-186 /opt/rust-sdk/src/libc138SLOP rm -rf /tmp/rustc /opt/rust-llvm /opt/rust-sdk/lib/rustlib/src139140# Cargo, by the kept compiler and library; the seed's Cargo drives its last build.141SOURCE /dist/static/rust/cargo.tar.gz 0254c9333333c4afc6c65b057bfd61d40715c5035aa0bfd84c54d0fd0d09a5fa /tmp/cargo.tar.gz142SLOP gzip -dc /tmp/cargo.tar.gz | tar -xf - -C /143SLOP rm /tmp/cargo.tar.gz144SLOP CWD /tmp/cargo/source cargo build -j 4 --offline --bin cargo --target-dir /tmp/cargo/build145SLOP cp /tmp/cargo/build/debug/cargo /usr/bin/cargo146SLOP mkdir -p /usr/share/licenses/cargo /usr/share/dolly/builds147SLOP cp /tmp/cargo/source/LICENSE-MIT /usr/share/licenses/cargo/LICENSE-MIT148SLOP cp /tmp/cargo/source/LICENSE-APACHE /usr/share/licenses/cargo/LICENSE-APACHE149SLOP cp /tmp/cargo/source/LICENSE-THIRD-PARTY /usr/share/licenses/cargo/LICENSE-THIRD-PARTY150SLOP cp /tmp/cargo/vendor/libgit2-sys-0.18.5+1.9.4/libgit2/COPYING /usr/share/licenses/cargo/libgit2-COPYING151SLOP cp /tmp/cargo/source/Cargo.lock /usr/share/dolly/builds/cargo.lock152SLOP rm -rf /tmp/cargo153154# The SDK's members are this recipe's now, not the seed's.155EXPORTS FOLDER rust-sdk /opt/rust-sdk156EXPORTS FOLDER rust-licenses /usr/share/licenses/rust157EXPORTS FOLDER cargo-licenses /usr/share/licenses/cargo158FILE /usr/share/dolly/builds/cargo.lock159SLOP rustc --version --verbose160SLOP rustdoc --version161SLOP cargo --version162163# The built toolchain builds and runs a program that uses a procedural macro.164FILE /tmp/rust-check/Cargo.toml165    [workspace]166    members = ["twice", "check"]167    resolver = "3"168FILE /tmp/rust-check/twice/Cargo.toml169    [package]170    name = "twice"171    version = "0.1.0"172    edition = "2024"173    [lib]174    proc-macro = true175FILE /tmp/rust-check/twice/src/lib.rs176    use proc_macro::TokenStream;177    #[proc_macro]178    pub fn twice(input: TokenStream) -> TokenStream {179        format!("({0}) + ({0})", input).parse().unwrap()180    }181FILE /tmp/rust-check/check/Cargo.toml182    [package]183    name = "check"184    version = "0.1.0"185    edition = "2024"186    [dependencies]187    twice = { path = "../twice" }188FILE /tmp/rust-check/check/src/main.rs189    fn main() { println!("built by cargo: {}", twice::twice!(21)); }190SLOP CWD /tmp/rust-check cargo build --offline191SLOP /tmp/rust-check/target/debug/check192SLOP rm -rf /tmp/rust-check193194ENTRY /bin/foreground -i /bin/slop195