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

Interface LanguageMethods

crates/test/src/lib.rs:1184–1288  ·  view source on GitHub ↗

Helper trait for each language to implement which encapsulates language-specific logic.

Source from the content-addressed store, hash-verified

1182/// Helper trait for each language to implement which encapsulates
1183/// language-specific logic.
1184trait LanguageMethods {
1185 /// Display name for this language, used in filenames.
1186 fn display(&self) -> &str;
1187
1188 /// Returns the prefix that this language uses to annotate configuration in
1189 /// the top of source files.
1190 ///
1191 /// This should be the language's line-comment syntax followed by `@`, e.g.
1192 /// `//@` for Rust or `;;@` for WebAssembly Text.
1193 fn comment_prefix_for_test_config(&self) -> Option<&str>;
1194
1195 /// Returns the extra permutations, if any, of arguments to use with codegen
1196 /// tests.
1197 ///
1198 /// This is used to run all codegen tests with a variety of bindings
1199 /// generator options. The first element in the tuple is a descriptive
1200 /// string that should be unique (used in file names) and the second elemtn
1201 /// is the list of arguments for that variant to pass to the bindings
1202 /// generator.
1203 fn codegen_test_variants(&self) -> &[(&str, &[&str])] {
1204 &[]
1205 }
1206
1207 /// Performs any one-time preparation necessary for this language, such as
1208 /// downloading or caching dependencies.
1209 fn prepare(&self, runner: &mut Runner) -> Result<()>;
1210
1211 /// Add some files to the generated directory _before_ calling bindgen
1212 fn generate_bindings_prepare(
1213 &self,
1214 _runner: &Runner,
1215 _bindgen: &Bindgen,
1216 _dir: &Path,
1217 ) -> Result<()> {
1218 Ok(())
1219 }
1220
1221 /// Generates bindings for `component` into `dir`.
1222 ///
1223 /// Runs `wit-bindgen` in aa subprocess to catch failures such as panics.
1224 fn generate_bindings(&self, runner: &Runner, bindgen: &Bindgen, dir: &Path) -> Result<()> {
1225 let name = match self.bindgen_name() {
1226 Some(name) => name,
1227 None => return Ok(()),
1228 };
1229 self.generate_bindings_prepare(runner, bindgen, dir)?;
1230 let mut cmd = Command::new(&runner.wit_bindgen);
1231 cmd.arg(name)
1232 .arg(&bindgen.wit_path)
1233 .arg("--world")
1234 .arg(format!("%{}", bindgen.world))
1235 .arg("--out-dir")
1236 .arg(dir);
1237
1238 match bindgen.wit_config.default_bindgen_args {
1239 Some(true) | None => {
1240 for arg in self.default_bindgen_args() {
1241 cmd.arg(arg);

Callers 7

run_codegen_testsMethod · 0.45
generate_bindingsMethod · 0.45
codegen_testMethod · 0.45
compile_componentMethod · 0.45
generate_bindingsMethod · 0.45
run_codegen_testsMethod · 0.45
generate_bindingsMethod · 0.45

Implementers 8

rust.rscrates/test/src/rust.rs
moonbit.rscrates/test/src/moonbit.rs
c.rscrates/test/src/c.rs
cpp.rscrates/test/src/cpp.rs
go.rscrates/test/src/go.rs
wat.rscrates/test/src/wat.rs
csharp.rscrates/test/src/csharp.rs
custom.rscrates/test/src/custom.rs

Calls

no outgoing calls

Tested by

no test coverage detected