MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / prepare

Method prepare

crates/test/src/rust.rs:100–164  ·  view source on GitHub ↗
(&self, runner: &mut Runner)

Source from the content-addressed store, hash-verified

98 }
99
100 fn prepare(&self, runner: &mut Runner) -> Result<()> {
101 let cwd = env::current_dir()?;
102 let opts = &runner.opts.rust;
103 let dir = cwd.join(&runner.opts.artifacts).join("rust");
104 let wit_bindgen = dir.join("wit-bindgen");
105
106 let wit_bindgen_dep = match &opts.rust_wit_bindgen_path {
107 Some(path) => format!("path = {:?}", cwd.join(path)),
108 None => {
109 let version = opts
110 .rust_wit_bindgen_version
111 .as_deref()
112 .unwrap_or(env!("CARGO_PKG_VERSION"));
113 format!("version = \"{version}\"")
114 }
115 };
116
117 super::write_if_different(
118 &wit_bindgen.join("Cargo.toml"),
119 &format!(
120 r#"
121[package]
122name = "tmp"
123
124[workspace]
125
126[dependencies]
127wit-bindgen = {{ {wit_bindgen_dep}, features = ['async-spawn', 'inter-task-wakeup', 'futures-stream'] }}
128futures = "0.3.31"
129
130[lib]
131path = 'lib.rs'
132 "#,
133 ),
134 )?;
135 super::write_if_different(&wit_bindgen.join("lib.rs"), "")?;
136
137 println!("Building `wit-bindgen` from crates.io...");
138 runner.run_command(
139 Command::new("cargo")
140 .current_dir(&wit_bindgen)
141 .arg("build")
142 .arg("-pwit-bindgen")
143 .arg("-pfutures")
144 .arg("--target")
145 .arg(&opts.rust_target),
146 )?;
147
148 let target_out_dir = wit_bindgen
149 .join("target")
150 .join(&opts.rust_target)
151 .join("debug");
152 let host_out_dir = wit_bindgen.join("target/debug");
153 let wit_bindgen_rlib = target_out_dir.join("libwit_bindgen.rlib");
154 let futures_rlib = target_out_dir.join("libfutures.rlib");
155 assert!(wit_bindgen_rlib.exists());
156 assert!(futures_rlib.exists());
157

Callers

nothing calls this directly

Calls 4

write_if_differentFunction · 0.85
newFunction · 0.85
joinMethod · 0.80
run_commandMethod · 0.80

Tested by

no test coverage detected