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

Method compile

crates/test/src/cpp.rs:107–179  ·  view source on GitHub ↗
(&self, runner: &Runner, compile: &crate::Compile)

Source from the content-addressed store, hash-verified

105 }
106
107 fn compile(&self, runner: &Runner, compile: &crate::Compile) -> anyhow::Result<()> {
108 let compiler = clangpp(runner);
109 let config = compile.component.deserialize_lang_config::<LangConfig>()?;
110
111 let cwd = std::env::current_dir()?;
112 let mut helper_dir = cwd.clone();
113 helper_dir.push("crates");
114 helper_dir.push("cpp");
115 helper_dir.push("helper-types");
116 // for expected
117 let mut helper_dir2 = cwd;
118 helper_dir2.push("crates");
119 helper_dir2.push("cpp");
120 helper_dir2.push("test_headers");
121
122 // Compile the C-based bindings to an object file.
123 let bindings_object = compile.output.with_extension("bindings.o");
124 let mut cmd = Command::new(clangpp(runner));
125 cmd.arg(
126 compile
127 .bindings_dir
128 .join(format!("{}.cpp", compile.component.bindgen.world)),
129 )
130 .arg("-I")
131 .arg(&compile.bindings_dir)
132 .arg("-I")
133 .arg(helper_dir.to_str().unwrap())
134 .arg("-I")
135 .arg(helper_dir2.to_str().unwrap())
136 .arg("-fno-exceptions")
137 .arg("-Wall")
138 .arg("-Wextra")
139 .arg("-Werror")
140 .arg("-Wno-unused-parameter")
141 .arg("-std=c++20")
142 .arg("-c")
143 .arg("-g")
144 .arg("-o")
145 .arg(&bindings_object);
146 runner.run_command(&mut cmd)?;
147
148 // Now compile the runner's source code to with the above object and the
149 // component-type object into a final component.
150 let mut cmd = Command::new(compiler);
151 cmd.arg(&compile.component.path)
152 .arg(&bindings_object)
153 .arg(compile.bindings_dir.join(format!(
154 "{}_component_type.o",
155 compile.component.bindgen.world
156 )))
157 .arg("-I")
158 .arg(&compile.bindings_dir)
159 .arg("-I")
160 .arg(helper_dir.to_str().unwrap())
161 .arg("-I")
162 .arg(helper_dir2.to_str().unwrap())
163 .arg("-fno-exceptions")
164 .arg("-Wall")

Callers

nothing calls this directly

Calls 5

clangppFunction · 0.85
newFunction · 0.85
joinMethod · 0.80
run_commandMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected