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
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions c2rust-transpile/rust-toolchain.toml
4 changes: 2 additions & 2 deletions c2rust-transpile/src/build_files/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions c2rust/rust-toolchain.toml
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 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).

Expand Down
2 changes: 1 addition & 1 deletion docs/README-developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions dynamic_instrumentation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 0 additions & 1 deletion dynamic_instrumentation/rust-toolchain

This file was deleted.

1 change: 1 addition & 0 deletions dynamic_instrumentation/rust-toolchain.toml
16 changes: 14 additions & 2 deletions dynamic_instrumentation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,27 @@ 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::<toml_edit::Document>()?;
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 {
metadata,
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.
Expand Down
1 change: 0 additions & 1 deletion examples/robotfindskitten/repo/rust/rust-toolchain

This file was deleted.

2 changes: 2 additions & 0 deletions examples/robotfindskitten/repo/rust/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly-2022-02-14"
1 change: 0 additions & 1 deletion manual/rust-toolchain

This file was deleted.

1 change: 1 addition & 0 deletions manual/rust-toolchain.toml
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly-2022-02-14"
components = ["rustfmt-preview", "rustc-dev", "rust-src"]
8 changes: 4 additions & 4 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import platform
import multiprocessing

from typing import List, Callable
from pathlib import Path
from typing import List

import plumbum as pb

from plumbum.machines import LocalCommand as Command
from query_toml import query_toml


class Colors:
Expand Down Expand Up @@ -99,9 +101,7 @@ 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:
CUSTOM_RUST_NAME = fh.readline().strip()
CUSTOM_RUST_NAME = query_toml(path=Path(ROOT_DIR).joinpath("rust-toolchain.toml"), query=("toolchain", "channel"))

LLVM_SKIP_SIGNATURE_CHECKS = False

Expand Down
6 changes: 3 additions & 3 deletions scripts/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ 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"
RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n')
# pull the rust version out of ../rust-toolchain.toml to keep things synced
RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml"
RUST_VER=$($SCRIPT_DIR/query_toml.py toolchain.channel $RUST_TOOLCHAIN_FILE)

docker pull "$BASE_IMAGE"
docker build -f $SCRIPT_DIR/../docker/Dockerfile \
Expand Down
7 changes: 2 additions & 5 deletions scripts/provision_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ 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"
export RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n')

# Rust and dependencies
RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain"
export RUST_VER=$(cat $RUST_TOOLCHAIN_FILE | tr -d '\n')
RUST_TOOLCHAIN_FILE="$SCRIPT_DIR/../rust-toolchain.toml"
export RUST_VER=$($SCRIPT_DIR/query_toml.py toolchain.channel $RUST_TOOLCHAIN_FILE)
"$SCRIPT_DIR/provision_rust.sh"
27 changes: 27 additions & 0 deletions scripts/query_toml.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pygments
typing;python_version<"3.5"
scan-build
pyyaml
toml
2 changes: 1 addition & 1 deletion scripts/test_rust_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions scripts/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down