Skip to content

Commit f348769

Browse files
author
mike dupont
committed
wip
1 parent 162a33d commit f348769

File tree

17 files changed

+2341
-174
lines changed

17 files changed

+2341
-174
lines changed

Cargo.lock

Lines changed: 1986 additions & 168 deletions
Large diffs are not rendered by default.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = [
44
# tidy-alphabetical-start
55
"compiler/rustc",
6-
"crates/rust-bootstrap", # Our new crate
6+
"crates/rust-bootstrap", "crates/syscall_instrumentation_macro", # Our new crate
77
"src/build_helper",
88
"src/rustc-std-workspace/rustc-std-workspace-alloc",
99
"src/rustc-std-workspace/rustc-std-workspace-core",

compiler/rustc_log/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
tracing-core = "=0.1.30" # FIXME(Nilstrieb) tracing has a deadlock: https://github.com/tokio-rs/tracing/issues/2635
8+
tracing-core = { path = "../../../mcp/monomcp/vendor/tracing-vendor/tracing/tracing-core", version = "0.1.30" } # FIXME(Nilstrieb) tracing has a deadlock: https://github.com/tokio-rs/tracing/issues/2635
99
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
1010
tracing-tree = "0.3.1"
1111
tracing.workspace = true

crates/rust-bootstrap/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ flate2 = "1.0"
2828
xz2 = "0.1"
2929
tempfile = "3.20.0"
3030
chrono = { version = "0.4", features = ["serde"] }
31-
once_cell = "1.19"
31+
once_cell = "1.19"
32+
cargo = { path = "../../../mcp/monomcp/vendor/cargo-rust-lang" }
33+
tracing-core = { path = "../../../mcp/monomcp/vendor/tracing-vendor/tracing/tracing-core" }
34+
tracing = { path = "../../../mcp/monomcp/vendor/tracing-vendor/tracing-0.1.41/tracing" }
35+
syscall_instrumentation_macro = { path = "../syscall_instrumentation_macro" }

crates/rust-bootstrap/src/bootstrap_stages/build_bootstrap/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn build_bootstrap(build_state: &BuildState) -> Result<(), Box<dyn Error>> {
110110
let additional_cargo_flags_str: Vec<&str> = additional_cargo_flags.iter().map(|s| s.as_str()).collect();
111111
args.extend_from_slice(&additional_cargo_flags_str);
112112

113-
command_executor::execute_and_report_command("cargo", &args)?;
113+
crate::cargo_integration::run_cargo_command(&["version"], &build_state.rust_root)?;
114114

115115
Ok(())
116116
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use cargo::GlobalContext;
2+
use cargo::ops::CompileOptions;
3+
use cargo::util::CargoResult;
4+
use cargo::core::compiler::UserIntent;
5+
6+
pub fn create_compile_options(gctx: &GlobalContext) -> CargoResult<CompileOptions> {
7+
CompileOptions::new(gctx, UserIntent::Build)
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use cargo::GlobalContext;
2+
use cargo::util::CargoResult;
3+
use std::env;
4+
use std::path::PathBuf;
5+
use cargo::core::shell::Shell;
6+
7+
pub fn init_global_context() -> CargoResult<GlobalContext> {
8+
// Hardcoding homedir to bypass potential issues with `home` crate in Termux.
9+
// This is a known and stable path in the Termux environment.
10+
let homedir = PathBuf::from("/data/data/com.termux/files/home/.cargo");
11+
let cwd = env::current_dir()?;
12+
let gctx = GlobalContext::new(Shell::new(), cwd, homedir);
13+
println!("GlobalContext homedir: {:?}", gctx.home().as_path_unlocked());
14+
Ok(gctx)
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::path::PathBuf;
2+
use cargo::core::Workspace;
3+
use cargo::GlobalContext;
4+
use cargo::util::CargoResult;
5+
6+
pub fn init_workspace<'gctx>(gctx: &'gctx GlobalContext, rust_root: &PathBuf) -> CargoResult<Workspace<'gctx>> {
7+
let manifest_path = rust_root.join("Cargo.toml");
8+
println!("init_workspace: manifest_path: {:?}", manifest_path);
9+
Workspace::new(&manifest_path, gctx)
10+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use std::error::Error;
2+
use std::path::PathBuf;
3+
4+
pub mod init_global_context;
5+
pub mod init_workspace;
6+
pub mod create_compile_options;
7+
pub mod parse_cargo_args;
8+
pub mod parse_global_args;
9+
10+
use cargo::ops::compile;
11+
use cargo::util::command_prelude::ArgMatchesExt;
12+
13+
pub fn run_cargo_command(args: &[&str], rust_root: &PathBuf) -> Result<(), Box<dyn Error>> {
14+
println!("Running cargo command via integration: {:?}", args);
15+
println!("rust_root: {:?}", rust_root);
16+
17+
// Temporarily change current directory to rust_root
18+
let original_cwd = std::env::current_dir()?;
19+
std::env::set_current_dir(rust_root)?;
20+
21+
let (global_matches, subcommand_args) = parse_global_args::parse_global_args(args)?;
22+
23+
let mut gctx = init_global_context::init_global_context()?;
24+
println!("gctx.cwd(): {:?}", gctx.cwd());
25+
26+
// Configure GlobalContext with global arguments
27+
gctx.configure(
28+
global_matches.verbose(),
29+
global_matches.flag("quiet"),
30+
global_matches.get_one::<String>("color").map(String::as_str),
31+
global_matches.flag("frozen"),
32+
global_matches.flag("locked"),
33+
global_matches.flag("offline"),
34+
&None, // target_dir, not handled by global args
35+
&global_matches.get_many::<String>("unstable-features").unwrap_or_default().cloned().collect::<Vec<String>>(),
36+
&global_matches.get_many::<String>("config").unwrap_or_default().cloned().collect::<Vec<String>>(),
37+
)?;
38+
39+
let ws = init_workspace::init_workspace(&gctx, rust_root)?;
40+
println!("ws.root(): {:?}", ws.root());
41+
42+
// Convert Vec<String> to Vec<&str> for parse_cargo_args
43+
let subcommand_args_str: Vec<&str> = subcommand_args.iter().map(|s| s.as_str()).collect();
44+
let compile_options = parse_cargo_args::parse_cargo_args(&gctx, &subcommand_args_str, rust_root)?;
45+
46+
compile(&ws, &compile_options)?;
47+
48+
// Restore original current directory
49+
std::env::set_current_dir(original_cwd)?;
50+
51+
Ok(())
52+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use cargo::GlobalContext;
2+
use cargo::ops::CompileOptions;
3+
use cargo::util::CargoResult;
4+
use cargo::core::compiler::UserIntent;
5+
use cargo::core::Workspace;
6+
use cargo::util::command_prelude::{CommandExt, ArgMatchesExt, ProfileChecking, subcommand};
7+
use std::path::PathBuf;
8+
use clap::{Command, ArgMatches};
9+
10+
pub fn parse_cargo_args<'gctx>(gctx: &'gctx GlobalContext, raw_args: &[&str], rust_root: &PathBuf) -> CargoResult<CompileOptions> {
11+
let command = subcommand("build")
12+
.about("Compile a local package and all of its dependencies")
13+
.arg_future_incompat_report()
14+
.arg_message_format()
15+
.arg_silent_suggestion()
16+
.arg_package_spec(
17+
"Package to build (see `cargo help pkgid`)",
18+
"Build all packages in the workspace",
19+
"Exclude packages from the build",
20+
)
21+
.arg_targets_all(
22+
"Build only this package's library",
23+
"Build only the specified binary",
24+
"Build all binaries",
25+
"Build only the specified example",
26+
"Build all examples",
27+
"Build only the specified test target",
28+
"Build all targets that have `test = true` set",
29+
"Build only the specified bench target",
30+
"Build all targets that have `bench = true` set",
31+
"Build all targets",
32+
)
33+
.arg_features()
34+
.arg_release("Build artifacts in release mode, with optimizations")
35+
.arg_redundant_default_mode("debug", "build", "release")
36+
.arg_profile("Build artifacts with the specified profile")
37+
.arg_parallel()
38+
.arg_target_triple("Build for the target triple")
39+
.arg_target_dir()
40+
.arg_artifact_dir()
41+
.arg_build_plan()
42+
.arg_unit_graph()
43+
.arg_timings()
44+
.arg_compile_time_deps()
45+
.arg_manifest_path()
46+
.arg_lockfile_path()
47+
.arg_ignore_rust_version();
48+
49+
let matches = command.try_get_matches_from(raw_args)?;
50+
51+
let ws = Workspace::new(rust_root, gctx)?;
52+
53+
let compile_options = matches.compile_options(gctx, UserIntent::Build, Some(&ws), ProfileChecking::Custom)?;
54+
55+
Ok(compile_options)
56+
}

0 commit comments

Comments
 (0)