From 748eb88de15cf38ecb040fcb1a2838347e6ef0e1 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 8 Jun 2022 09:36:42 -0700 Subject: [PATCH 01/11] Converted all `rust-toolchain` files to the more expressive `rust-toolchain.toml` format. --- c2rust-transpile/rust-toolchain.toml | 1 + c2rust/rust-toolchain.toml | 1 + dynamic_instrumentation/rust-toolchain | 1 - dynamic_instrumentation/rust-toolchain.toml | 1 + examples/robotfindskitten/repo/rust/rust-toolchain | 1 - examples/robotfindskitten/repo/rust/rust-toolchain.toml | 2 ++ manual/rust-toolchain | 1 - manual/rust-toolchain.toml | 1 + rust-toolchain | 1 - rust-toolchain.toml | 2 ++ 10 files changed, 8 insertions(+), 4 deletions(-) create mode 120000 c2rust-transpile/rust-toolchain.toml create mode 120000 c2rust/rust-toolchain.toml delete mode 120000 dynamic_instrumentation/rust-toolchain create mode 120000 dynamic_instrumentation/rust-toolchain.toml delete mode 100644 examples/robotfindskitten/repo/rust/rust-toolchain create mode 100644 examples/robotfindskitten/repo/rust/rust-toolchain.toml delete mode 120000 manual/rust-toolchain create mode 120000 manual/rust-toolchain.toml delete mode 100644 rust-toolchain create mode 100644 rust-toolchain.toml diff --git a/c2rust-transpile/rust-toolchain.toml b/c2rust-transpile/rust-toolchain.toml new file mode 120000 index 0000000000..43fe0ada68 --- /dev/null +++ b/c2rust-transpile/rust-toolchain.toml @@ -0,0 +1 @@ +../rust-toolchain.toml \ No newline at end of file diff --git a/c2rust/rust-toolchain.toml b/c2rust/rust-toolchain.toml new file mode 120000 index 0000000000..43fe0ada68 --- /dev/null +++ b/c2rust/rust-toolchain.toml @@ -0,0 +1 @@ +../rust-toolchain.toml \ No newline at end of file diff --git a/dynamic_instrumentation/rust-toolchain b/dynamic_instrumentation/rust-toolchain deleted file mode 120000 index 9327ba4034..0000000000 --- a/dynamic_instrumentation/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -../rust-toolchain \ No newline at end of file diff --git a/dynamic_instrumentation/rust-toolchain.toml b/dynamic_instrumentation/rust-toolchain.toml new file mode 120000 index 0000000000..43fe0ada68 --- /dev/null +++ b/dynamic_instrumentation/rust-toolchain.toml @@ -0,0 +1 @@ +../rust-toolchain.toml \ No newline at end of file diff --git a/examples/robotfindskitten/repo/rust/rust-toolchain b/examples/robotfindskitten/repo/rust/rust-toolchain deleted file mode 100644 index fc40182b3c..0000000000 --- a/examples/robotfindskitten/repo/rust/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2019-12-05 diff --git a/examples/robotfindskitten/repo/rust/rust-toolchain.toml b/examples/robotfindskitten/repo/rust/rust-toolchain.toml new file mode 100644 index 0000000000..9b8653de4b --- /dev/null +++ b/examples/robotfindskitten/repo/rust/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2019-12-05" diff --git a/manual/rust-toolchain b/manual/rust-toolchain deleted file mode 120000 index 9327ba4034..0000000000 --- a/manual/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -../rust-toolchain \ No newline at end of file diff --git a/manual/rust-toolchain.toml b/manual/rust-toolchain.toml new file mode 120000 index 0000000000..43fe0ada68 --- /dev/null +++ b/manual/rust-toolchain.toml @@ -0,0 +1 @@ +../rust-toolchain.toml \ No newline at end of file diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index f24eb00eda..0000000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2022-02-14 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000000..5eb4c1c9dc --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2022-02-14" From 7f237faabc2452e49f3ae9627e94bb117ed28051 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 8 Jun 2022 09:39:14 -0700 Subject: [PATCH 02/11] Converted all `rust-toolchain` strings to `rust-toolchain.toml`. --- c2rust-transpile/src/build_files/mod.rs | 4 ++-- docker/Dockerfile | 2 +- docs/README-developers.md | 2 +- scripts/common.py | 3 ++- scripts/docker_build.sh | 4 ++-- scripts/provision_mac.sh | 4 ++-- scripts/test_rust_refactor.py | 2 +- scripts/test_translator.py | 4 ++-- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/c2rust-transpile/src/build_files/mod.rs b/c2rust-transpile/src/build_files/mod.rs index 47527b443d..2f9dea8afe 100644 --- a/c2rust-transpile/src/build_files/mod.rs +++ b/c2rust-transpile/src/build_files/mod.rs @@ -259,8 +259,8 @@ fn emit_lib_rs( /// If we translate variadic functions, the output will only compile /// on a nightly toolchain until the `c_variadics` feature is stable. fn emit_rust_toolchain(tcfg: &TranspilerConfig, build_dir: &Path) { - let output_path = build_dir.join("rust-toolchain"); - let output = include_str!("../../../rust-toolchain").to_string(); + let output_path = build_dir.join("rust-toolchain.toml"); + let output = include_str!("../../rust-toolchain.toml").to_string(); maybe_write_to_file(&output_path, output, tcfg.overwrite_existing); } diff --git a/docker/Dockerfile b/docker/Dockerfile index 0f9d820798..95339eba6f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ # Docker image for c2rust CI and containerized development. # Multi-distro via optional BASE_IMAGE argument. -# RUST_VER argument should be set to the contents of the rust-toolchain file in +# RUST_VER argument should be set to the contents of the rust-toolchain.toml file in # the repo root (because dockerfiles can't access files above the location where # `docker build` is run). diff --git a/docs/README-developers.md b/docs/README-developers.md index c2ca482c95..fe4c02d553 100644 --- a/docs/README-developers.md +++ b/docs/README-developers.md @@ -27,7 +27,7 @@ Then run `./scripts/provision_mac.sh`. - `python-dev` - `python` >= 3.6 - [python dependencies](../scripts/requirements.txt) - - `rustc` [version](../rust-toolchain) + - `rustc` [version](../rust-toolchain.toml) - `rustfmt-preview` component for the above `rustc` version - `libssl` (development library, dependency of the refactoring tool) diff --git a/scripts/common.py b/scripts/common.py index 3a1d0b46f0..4862a37477 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -98,9 +98,10 @@ class Config: CC_DB_JSON = "compile_commands.json" # Look up rust toolchain from repo root - with open(os.path.join(ROOT_DIR, "rust-toolchain")) as fh: + with open(os.path.join(ROOT_DIR, "rust-toolchain.toml")) as fh: CUSTOM_RUST_NAME = fh.readline().strip() + LLVM_SKIP_SIGNATURE_CHECKS = False """ diff --git a/scripts/docker_build.sh b/scripts/docker_build.sh index 71c761837b..ff70d2dd22 100755 --- a/scripts/docker_build.sh +++ b/scripts/docker_build.sh @@ -27,8 +27,8 @@ build_image() { BASE_IMAGE=${1} IMAGE_TAG=$(echo ${BASE_IMAGE} | tr -s :/ - ) # replace colons and slashes with hyphens - # pull the rust version out of ../rust-toolchain to keep things synched - RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain" + # pull the rust version out of ../rust-toolchain.toml to keep things synched + RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml" RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n') docker pull "$BASE_IMAGE" diff --git a/scripts/provision_mac.sh b/scripts/provision_mac.sh index d6c1e64958..01980cedef 100755 --- a/scripts/provision_mac.sh +++ b/scripts/provision_mac.sh @@ -34,10 +34,10 @@ type -P "pip3" >/dev/null || { pip3 install --user --upgrade pip pip3 install -r "$SCRIPT_DIR/requirements.txt" --user --disable-pip-version-check -RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain" +RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml" export RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n') # Rust and dependencies -RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain" +RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml" export RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n') "$SCRIPT_DIR/provision_rust.sh" diff --git a/scripts/test_rust_refactor.py b/scripts/test_rust_refactor.py index 6b79dd321b..20f79b2c46 100755 --- a/scripts/test_rust_refactor.py +++ b/scripts/test_rust_refactor.py @@ -91,7 +91,7 @@ def main(): setup_logging() # NOTE: it seems safe to disable this check since we now - # that we use a rust-toolchain file for rustc versioning. + # that we use a rust-toolchain.toml file for rustc versioning. # ensure_rustc_version(c.CUSTOM_RUST_RUSTC_VERSION) # TODO: update rustfmt version check once c2rust-refactor bitrot has been fixed # ensure_rustfmt_version() diff --git a/scripts/test_translator.py b/scripts/test_translator.py index 1205e508da..7a02d3adc9 100755 --- a/scripts/test_translator.py +++ b/scripts/test_translator.py @@ -422,7 +422,7 @@ def run(self) -> List[TestOutcome]: self.generated_files["rust_src"].append(self.full_path + "/src/Cargo.toml") self.generated_files["rust_src"].append(self.full_path + "/src/build.rs") self.generated_files["rust_src"].append(self.full_path + "/src/c2rust-lib.rs") - self.generated_files["rust_src"].append(self.full_path + "/src/rust-toolchain") + self.generated_files["rust_src"].append(self.full_path + "/src/rust-toolchain.toml") _, rust_file_short = os.path.split(translated_rust_file.path) extensionless_rust_file, _ = os.path.splitext(rust_file_short) @@ -657,7 +657,7 @@ def main() -> None: die(msg, errno.ENOENT) # NOTE: it seems safe to disable this check since we now - # that we use a rust-toolchain file for rustc versioning. + # that we use a rust-toolchain.toml file for rustc versioning. # ensure_rustc_version(c.CUSTOM_RUST_RUSTC_VERSION) if not test_directories: From 216e3857ab3fdb5dc1ea7ca6e81d2a063c97b0ab Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 8 Jun 2022 09:53:49 -0700 Subject: [PATCH 03/11] Fixed a read of `rust-toolchain.toml` that reads the toolchain channel using the `toml` library to parse. --- scripts/common.py | 7 +++++-- scripts/requirements.txt | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/common.py b/scripts/common.py index 4862a37477..e28a2b9dc8 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -10,7 +10,9 @@ import argparse import platform import multiprocessing +import toml +from pathlib import Path from typing import List, Callable import plumbum as pb @@ -98,8 +100,9 @@ class Config: CC_DB_JSON = "compile_commands.json" # Look up rust toolchain from repo root - with open(os.path.join(ROOT_DIR, "rust-toolchain.toml")) as fh: - CUSTOM_RUST_NAME = fh.readline().strip() + rust_toolchain_str = Path(ROOT_DIR).joinpath("rust-toolchain.toml").read_text() + rust = toml.loads(rust_toolchain_str) + CUSTOM_RUST_NAME = rust["toolchain"]["channel"] LLVM_SKIP_SIGNATURE_CHECKS = False diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 4a9af6ff4f..39999614fe 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -9,3 +9,4 @@ pygments typing;python_version<"3.5" scan-build pyyaml +toml From ec13e58b6f1481691a42756edf669bfb36c212cf Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 8 Jun 2022 10:30:12 -0700 Subject: [PATCH 04/11] Added the `rustup` components to the `rust-toolchain.toml` file. I still left them in `provision_rust.sh` as well, even though they're not strictly needed, because it will help to have them cached in the Docker image. Ideally, I think we'd put c2rust itself (or at least parts of it) into the Docker image as well for caching purposes. --- rust-toolchain.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 5eb4c1c9dc..72a896fdd2 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,3 @@ [toolchain] channel = "nightly-2022-02-14" +components = ["rustfmt-preview", "rustc-dev", "rust-src"] From b02c74026258cf0b52bd110fc9049361243f4099 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 8 Jun 2022 11:41:42 -0700 Subject: [PATCH 05/11] Updated the `rust-toolchain.toml` in an example to match the root `rust-toolchain.toml`. I believe they should be in sync because this one is produced by copying the root one. --- examples/robotfindskitten/repo/rust/rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/robotfindskitten/repo/rust/rust-toolchain.toml b/examples/robotfindskitten/repo/rust/rust-toolchain.toml index 9b8653de4b..5eb4c1c9dc 100644 --- a/examples/robotfindskitten/repo/rust/rust-toolchain.toml +++ b/examples/robotfindskitten/repo/rust/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2019-12-05" +channel = "nightly-2022-02-14" From d8973335b301c4aaec468fd38e7ce2fc6067edb6 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 13 Jul 2022 10:37:09 -0700 Subject: [PATCH 06/11] Clarified that we need the channel not the contents of the `rust-toolchain.toml` file now. --- docker/Dockerfile | 2 +- scripts/docker_build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 95339eba6f..674dd14c99 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ # Docker image for c2rust CI and containerized development. # Multi-distro via optional BASE_IMAGE argument. -# RUST_VER argument should be set to the contents of the rust-toolchain.toml file in +# RUST_VER argument should be set to the channel of the rust-toolchain.toml file in # the repo root (because dockerfiles can't access files above the location where # `docker build` is run). diff --git a/scripts/docker_build.sh b/scripts/docker_build.sh index ff70d2dd22..5fc14e46f2 100755 --- a/scripts/docker_build.sh +++ b/scripts/docker_build.sh @@ -27,7 +27,7 @@ build_image() { BASE_IMAGE=${1} IMAGE_TAG=$(echo ${BASE_IMAGE} | tr -s :/ - ) # replace colons and slashes with hyphens - # pull the rust version out of ../rust-toolchain.toml to keep things synched + # pull the rust version out of ../rust-toolchain.toml to keep things synced RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml" RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n') From 2266c1bffcddb2aa867c7360a9c018cbcb71ee45 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 13 Jul 2022 10:38:05 -0700 Subject: [PATCH 07/11] Deleted duplicate `RUST_VER` parsing in `provision_mac.sh`. --- scripts/provision_mac.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/provision_mac.sh b/scripts/provision_mac.sh index 01980cedef..8ae1becaa3 100755 --- a/scripts/provision_mac.sh +++ b/scripts/provision_mac.sh @@ -34,9 +34,6 @@ type -P "pip3" >/dev/null || { pip3 install --user --upgrade pip pip3 install -r "$SCRIPT_DIR/requirements.txt" --user --disable-pip-version-check -RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml" -export RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n') - # Rust and dependencies RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml" export RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n') From ced7889088677e0515a5b9b5e1acd99ddd2da928 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 13 Jul 2022 10:55:09 -0700 Subject: [PATCH 08/11] Refactored the `rust_toolchain.toml` `toolchain.channel` lookup into `query_toml.py`, which is also a CLI and is used in `docker_build.sh` and `provision_mac.sh` to query the channel now. --- scripts/common.py | 8 +++----- scripts/docker_build.sh | 2 +- scripts/provision_mac.sh | 2 +- scripts/query_toml.py | 27 +++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100755 scripts/query_toml.py diff --git a/scripts/common.py b/scripts/common.py index e28a2b9dc8..9346cbac57 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -17,6 +17,8 @@ import plumbum as pb +from scripts.query_toml import query_toml + class Colors: # Terminal escape codes @@ -99,11 +101,7 @@ class Config: CC_DB_JSON = "compile_commands.json" - # Look up rust toolchain from repo root - rust_toolchain_str = Path(ROOT_DIR).joinpath("rust-toolchain.toml").read_text() - rust = toml.loads(rust_toolchain_str) - CUSTOM_RUST_NAME = rust["toolchain"]["channel"] - + CUSTOM_RUST_NAME = query_toml(path=Path(ROOT_DIR).joinpath("rust-toolchain.toml"), query=("toolchain", "channel")) LLVM_SKIP_SIGNATURE_CHECKS = False diff --git a/scripts/docker_build.sh b/scripts/docker_build.sh index 5fc14e46f2..26e4c08d76 100755 --- a/scripts/docker_build.sh +++ b/scripts/docker_build.sh @@ -29,7 +29,7 @@ build_image() { # pull the rust version out of ../rust-toolchain.toml to keep things synced RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml" - RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n') + RUST_VER=$($SCRIPT_DIR/query_toml.py toolchain.channel $RUST_TOOLCHAIN_FILE) docker pull "$BASE_IMAGE" docker build -f $SCRIPT_DIR/../docker/Dockerfile \ diff --git a/scripts/provision_mac.sh b/scripts/provision_mac.sh index 8ae1becaa3..8530c20718 100755 --- a/scripts/provision_mac.sh +++ b/scripts/provision_mac.sh @@ -36,5 +36,5 @@ pip3 install -r "$SCRIPT_DIR/requirements.txt" --user --disable-pip-version-chec # Rust and dependencies RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml" -export RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n') +export RUST_VER=$($SCRIPT_DIR/query_toml.py toolchain.channel $RUST_TOOLCHAIN_FILE) "$SCRIPT_DIR/provision_rust.sh" diff --git a/scripts/query_toml.py b/scripts/query_toml.py new file mode 100755 index 0000000000..ec90c6f9f0 --- /dev/null +++ b/scripts/query_toml.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +from argparse import ArgumentParser +from pathlib import Path +from typing import Any, Iterable +import toml + + +def query_toml(path: Path, query: Iterable[str]) -> Any: + result = toml.load(path) + for field in query: + if isinstance(result, list): + field = int(field) + result = result[field] + return result + + +def main(): + parser = ArgumentParser() + parser.add_argument("query", type=str, help="the TOML query, with fields separated by .") + parser.add_argument("path", type=Path, help="the path to a TOML file") + args = parser.parse_args() + print(query_toml(path=args.path, query=args.query.split("."))) + + +if __name__ == "__main__": + main() From 8a026fb8893220352feb2b11e611b62274109e3b Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Mon, 8 Aug 2022 22:01:16 -0700 Subject: [PATCH 09/11] Updated to parsing `rust-toolchain.toml` in `c2rust-instrument` using `toml-edit` (as `cargo` does). --- Cargo.lock | 28 ++++++++++++++++++++++++++++ dynamic_instrumentation/Cargo.toml | 3 +++ dynamic_instrumentation/src/main.rs | 16 ++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02d2e5edf2..e677d435a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -132,6 +132,12 @@ version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" + [[package]] name = "c2rust" version = "0.16.0" @@ -238,6 +244,7 @@ dependencies = [ "lazy_static", "log", "rustc-private-link", + "toml_edit", ] [[package]] @@ -467,6 +474,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "combine" +version = "4.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a604e93b79d1808327a6fca85a6f2d69de66461e7620f5a4cbf5fb4d1d7c948" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "console" version = "0.15.1" @@ -1335,6 +1352,17 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" +[[package]] +name = "toml_edit" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5376256e44f2443f8896ac012507c19a012df0fe8758b55246ae51a2279db51f" +dependencies = [ + "combine", + "indexmap", + "itertools", +] + [[package]] name = "tracing" version = "0.1.36" diff --git a/dynamic_instrumentation/Cargo.toml b/dynamic_instrumentation/Cargo.toml index ffeae2414d..ebd8170131 100644 --- a/dynamic_instrumentation/Cargo.toml +++ b/dynamic_instrumentation/Cargo.toml @@ -15,6 +15,9 @@ fs-err = "2" clap = { version = "3.2", features = ["derive"] } cargo_metadata = "0.15" camino = "1.0" +# Used for parsing `rust-toolchain.toml`. +# We don't need to edit at all, but `cargo` uses `toml-edit`, so we want to match it. +toml_edit = "0.14" [build-dependencies] rustc-private-link = { path = "../rustc-private-link" } diff --git a/dynamic_instrumentation/src/main.rs b/dynamic_instrumentation/src/main.rs index 36be1a88b5..c12d6bfdcd 100644 --- a/dynamic_instrumentation/src/main.rs +++ b/dynamic_instrumentation/src/main.rs @@ -268,6 +268,19 @@ fn rustc_wrapper() -> anyhow::Result<()> { Ok(()) } +/// Set `$RUST_TOOLCHAIN` to the toolchain channel specified in `rust-toolchain.toml`. +/// This ensures that we use a toolchain compatible with the `rustc` private crates that we linked to. +fn set_rust_toolchain() -> anyhow::Result<()> { + let toml = include_str!("../rust-toolchain.toml"); + // Couldn't find an `include_toml!` macro to do this at compile time. + let doc = toml.parse::()?; + let channel = doc["toolchain"]["channel"].as_str(); + if let Some(toolchain) = channel { + env::set_var("RUSTUP_TOOLCHAIN", toolchain); + } + Ok(()) +} + /// Run as a `cargo` wrapper/plugin, the default invocation. fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> { let Args { @@ -275,8 +288,7 @@ fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> { mut cargo_args, } = Args::parse(); - // Ensure we use a toolchain compatible with the `rustc` private crates we linked to. - env::set_var("RUSTUP_TOOLCHAIN", include_str!("../rust-toolchain").trim()); + set_rust_toolchain()?; // Resolve the sysroot once in the [`cargo_wrapper`] // so that we don't need all of the [`rustc_wrapper`]s to have to do it. From 88a4cd99ed2ae1631be18e02ec9b73e14c8f8c6b Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 9 Aug 2022 11:28:22 -0700 Subject: [PATCH 10/11] Removed unused Python imports. --- scripts/common.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/common.py b/scripts/common.py index 9346cbac57..ca1b98fe43 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -10,10 +10,9 @@ import argparse import platform import multiprocessing -import toml from pathlib import Path -from typing import List, Callable +from typing import List import plumbum as pb From 528fba5666678e6f2ef4a1be20fdc26070dddd35 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 9 Aug 2022 12:27:31 -0700 Subject: [PATCH 11/11] Fixed bad import path. --- scripts/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/common.py b/scripts/common.py index ca1b98fe43..7c8462d0e3 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -16,7 +16,7 @@ import plumbum as pb -from scripts.query_toml import query_toml +from query_toml import query_toml class Colors: