Helper trait for each language to implement which encapsulates language-specific logic.
| 1182 | /// Helper trait for each language to implement which encapsulates |
| 1183 | /// language-specific logic. |
| 1184 | trait 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); |
no outgoing calls
no test coverage detected