Skip to content

Commit 81ab2a9

Browse files
fix: use fewer rustup deps for expression
1 parent 1aec980 commit 81ab2a9

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

expression/src/dependencies.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
use crate::error::{self, ExpressionExecutionError};
22
use snafu::ResultExt;
3-
use std::path::{Path, PathBuf};
3+
use std::{
4+
fs::File,
5+
io::{BufWriter, Write},
6+
path::{Path, PathBuf},
7+
};
48

59
pub type Result<T, E = ExpressionExecutionError> = std::result::Result<T, E>;
610

711
const DEPS_CARGO_TOML: &[u8] = std::include_bytes!("../deps-workspace/Cargo.toml");
812
const DEPS_CARGO_LOCK: &[u8] = std::include_bytes!("../deps-workspace/Cargo.lock");
913
const DEPS_LIB_RS: &[u8] = std::include_bytes!("../deps-workspace/lib.rs");
10-
const RUST_TOOLCHAIN_TOML: &[u8] = std::include_bytes!("../../rust-toolchain.toml");
14+
const RUST_TOOLCHAIN_TOML: &str = std::include_str!("../../rust-toolchain.toml");
1115

1216
/// A pre-built workspace for linking dependencies.
1317
///
@@ -57,13 +61,27 @@ impl ExpressionDependencies {
5761
}
5862

5963
fn copy_deps_workspace(cargo_workspace: &Path) -> Result<(), std::io::Error> {
64+
const COMPONENTS_LINE_PREFIX: &str = "components = ";
65+
const REPLACEMENT_COMPONENTS: &str = r#"["rustc", "cargo", "rust-std"]"#;
66+
6067
std::fs::write(cargo_workspace.join("Cargo.toml"), DEPS_CARGO_TOML)?;
6168
std::fs::write(cargo_workspace.join("Cargo.lock"), DEPS_CARGO_LOCK)?;
6269
std::fs::write(cargo_workspace.join("lib.rs"), DEPS_LIB_RS)?;
63-
std::fs::write(
64-
cargo_workspace.join("rust-toolchain.toml"),
65-
RUST_TOOLCHAIN_TOML,
66-
)?;
70+
71+
let file = File::create(cargo_workspace.join("rust-toolchain.toml"))?;
72+
let mut file = BufWriter::new(file);
73+
74+
for line in RUST_TOOLCHAIN_TOML.lines() {
75+
if line.starts_with(COMPONENTS_LINE_PREFIX) {
76+
writeln!(
77+
&mut file,
78+
"{COMPONENTS_LINE_PREFIX}{REPLACEMENT_COMPONENTS}"
79+
)?;
80+
} else {
81+
writeln!(&mut file, "{line}")?;
82+
}
83+
}
84+
6785
Ok(())
6886
}
6987
}

0 commit comments

Comments
 (0)