Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export/README

## Required

- [Rebuild a target directory when its std changes](/quest/m2/ts-sysroot-fingerprint.md) - a new std sysroot rebuilds what depends on std, so no E0460 until a clean
- [Byte slices without objects](/quest/m2/ts-byte-views/README.md) - reading through a translated cursor allocates no object per read
- [Async in the TypeScript translator](/quest/m2/ts-async.md) - moq-net's and kio's async code translates with Rust's lazy futures
- [Shared ownership](/quest/m2/ts-shared.md) - `Arc`/`Rc`/`Weak` keep exact counts, and locks and atomics become plain values
Expand Down
33 changes: 0 additions & 33 deletions quest/m2/ts-sysroot-fingerprint.md

This file was deleted.

6 changes: 5 additions & 1 deletion ts/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ fn try_run(args: &[String]) -> Result<ExitCode, String> {
};
let sysroot = sysroot()?;
// `cargo clean` reads the profiles too. The sysroot is absolute for the wrapper, which
// cargo runs elsewhere, and empty for none.
// cargo runs elsewhere, and empty for none. The wrapper's version names it, so cargo
// must not cache that version by the executables alone, and must hash all of it into
// `-C metadata`, which on a nightly it does only with `-Zseparate-nightlies`.
let env = [
(config::env::CONFIG, args.config.as_os_str()),
output,
("CARGO_UNSTABLE_PROFILE_RUSTFLAGS", "true".as_ref()),
(config::env::SYSROOT, sysroot.as_deref().unwrap_or("").as_ref()),
("CARGO_CACHE_RUSTC_INFO", "0".as_ref()),
("CARGO_UNSTABLE_SEPARATE_NIGHTLIES", "true".as_ref()),
];
let mut cargo = profile_args(sysroot.is_none());
// The profile `PROFILE` sets, which cargo refuses to combine with one the cargo args
Expand Down
11 changes: 10 additions & 1 deletion ts/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ use crate::{cli, lower, program};
/// Run as rustc, with `args` as cargo passed them: the wrapped rustc's path first.
pub fn run(args: Vec<String>) -> ExitCode {
rust2_driver::rustc::run("rust2-ts", args, |args| {
let sysroot = cli::sysroot()?;
// Cargo's query of the compiler, whose answer it hashes into every unit's fingerprint
// and `-C metadata`: the sysroot is part of what compiles them, so a target
// directory keeps what it checks against each sysroot apart.
if args[1..] == ["-vV"]
&& let Some(sysroot) = &sysroot
{
println!("rust2-ts-sysroot: {sysroot}");
}
// The target's crates only: build scripts and proc macros run on the host, with its std.
if args.windows(2).any(|w| w[0] == "--target" && w[1] == cli::TARGET)
&& let Some(sysroot) = cli::sysroot()?
&& let Some(sysroot) = sysroot
{
args.extend(["--sysroot".into(), sysroot]);
}
Expand Down
49 changes: 49 additions & 0 deletions ts/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,55 @@ fn census() {
);
}

/// One target directory keeps what it checked against each sysroot apart: a crate
/// checked against another std is never loaded. Switching sysroots checks a registry
/// dependency again, and switching back checks none. The other sysroot is the same std by
/// another path, which is all that tells sysroots apart.
#[test]
fn sysroot() {
let Some(std) = std::env::var("RUST2_TS_SYSROOT").ok().filter(|dir| !dir.is_empty()) else {
// Each target directory checks its own std instead.
return;
};
let name = Path::new(&std).file_name().unwrap().to_str().unwrap();
let other = format!("{std}/../{name}");
let dir = scratch().join("sysroot");
let _ = std::fs::remove_dir_all(&dir);
let checked = |sysroot: &str| {
let output = Command::new(env!("CARGO_BIN_EXE_rust2-ts"))
.arg("--config")
.arg(fixture("reject").join("census.toml"))
.arg("--census")
.arg(dir.join("census.md"))
.env("CARGO_TARGET_DIR", dir.join("build"))
.env("RUST2_TS_SYSROOT", sysroot)
.output()
.expect("running rust2-ts");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
output.status.success(),
"the census against {sysroot} failed:\n{stderr}"
);
stderr
.lines()
.filter_map(|line| line.trim_start().strip_prefix("Checking "))
.map(|line| line.split(' ').next().unwrap().to_string())
.collect::<Vec<_>>()
};
let all = checked(&std);
assert!(all.iter().any(|c| c == "bytes"), "bytes was not checked: {all:?}");
assert_eq!(
checked(&other),
all,
"switching to {other} kept a crate checked against {std}"
);
assert_eq!(
checked(&std),
["reject-fixture"],
"switching back to {std} checked its crates again"
);
}

/// Selects the fixture's own getrandom backend, which `rand::rng()` seeds from natively:
/// wasm32 has no OS to read. Only getrandom's flags change, so nothing else rebuilds.
const GETRANDOM: &str = r#"profile.dev.package.getrandom.rustflags=["--cfg", 'getrandom_backend="custom"']"#;
Expand Down