|
1 | 1 | use crate::error::{self, ExpressionExecutionError}; |
2 | 2 | use snafu::ResultExt; |
3 | | -use std::path::{Path, PathBuf}; |
| 3 | +use std::{ |
| 4 | + fs::File, |
| 5 | + io::{BufWriter, Write}, |
| 6 | + path::{Path, PathBuf}, |
| 7 | +}; |
4 | 8 |
|
5 | 9 | pub type Result<T, E = ExpressionExecutionError> = std::result::Result<T, E>; |
6 | 10 |
|
7 | 11 | const DEPS_CARGO_TOML: &[u8] = std::include_bytes!("../deps-workspace/Cargo.toml"); |
8 | 12 | const DEPS_CARGO_LOCK: &[u8] = std::include_bytes!("../deps-workspace/Cargo.lock"); |
9 | 13 | 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"); |
11 | 15 |
|
12 | 16 | /// A pre-built workspace for linking dependencies. |
13 | 17 | /// |
@@ -57,13 +61,27 @@ impl ExpressionDependencies { |
57 | 61 | } |
58 | 62 |
|
59 | 63 | 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 | + |
60 | 67 | std::fs::write(cargo_workspace.join("Cargo.toml"), DEPS_CARGO_TOML)?; |
61 | 68 | std::fs::write(cargo_workspace.join("Cargo.lock"), DEPS_CARGO_LOCK)?; |
62 | 69 | 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 | + |
67 | 85 | Ok(()) |
68 | 86 | } |
69 | 87 | } |
|
0 commit comments