Skip to content

Commit 5df5103

Browse files
committed
genmc/build: Drop LLVM dependency from build
GenMC (v0.14.1) no longer depends on LLVM when built as a library. This commit adjust genmc building and shim accordingly.
1 parent 4ea921a commit 5df5103

File tree

2 files changed

+6
-60
lines changed

2 files changed

+6
-60
lines changed

src/tools/miri/genmc-sys/build.rs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -140,51 +140,6 @@ mod downloading {
140140
}
141141
}
142142

143-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
144-
/// The linked LLVM version is in the generated `config.h`` file, which we parse and use to link to LLVM.
145-
/// Returns c++ compiler definitions required for building with/including LLVM, and the include path for LLVM headers.
146-
fn link_to_llvm(config_file: &Path) -> (String, String) {
147-
/// Search a string for a line matching `//@VARIABLE_NAME: VARIABLE CONTENT`
148-
fn extract_value<'a>(input: &'a str, name: &str) -> Option<&'a str> {
149-
input
150-
.lines()
151-
.find_map(|line| line.strip_prefix("//@")?.strip_prefix(name)?.strip_prefix(": "))
152-
}
153-
154-
let file_content = std::fs::read_to_string(&config_file).unwrap_or_else(|err| {
155-
panic!("GenMC config file ({}) should exist, but got errror {err:?}", config_file.display())
156-
});
157-
158-
let llvm_definitions = extract_value(&file_content, "LLVM_DEFINITIONS")
159-
.expect("Config file should contain LLVM_DEFINITIONS");
160-
let llvm_include_dirs = extract_value(&file_content, "LLVM_INCLUDE_DIRS")
161-
.expect("Config file should contain LLVM_INCLUDE_DIRS");
162-
let llvm_library_dir = extract_value(&file_content, "LLVM_LIBRARY_DIR")
163-
.expect("Config file should contain LLVM_LIBRARY_DIR");
164-
let llvm_config_path = extract_value(&file_content, "LLVM_CONFIG_PATH")
165-
.expect("Config file should contain LLVM_CONFIG_PATH");
166-
167-
// Add linker search path.
168-
let lib_dir = PathBuf::from_str(llvm_library_dir).unwrap();
169-
println!("cargo::rustc-link-search=native={}", lib_dir.display());
170-
171-
// Add libraries to link.
172-
let output = std::process::Command::new(llvm_config_path)
173-
.arg("--libs") // Print the libraries to link to (space-separated list)
174-
.output()
175-
.expect("failed to execute llvm-config");
176-
let llvm_link_libs =
177-
String::try_from(output.stdout).expect("llvm-config output should be a valid string");
178-
179-
for link_lib in llvm_link_libs.trim().split(" ") {
180-
let link_lib =
181-
link_lib.strip_prefix("-l").expect("Linker parameter should start with \"-l\"");
182-
println!("cargo::rustc-link-lib=dylib={link_lib}");
183-
}
184-
185-
(llvm_definitions.to_string(), llvm_include_dirs.to_string())
186-
}
187-
188143
/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
189144
fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
190145
// Give each step a separate build directory to prevent interference.
@@ -204,6 +159,7 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
204159
.always_configure(always_configure) // We force running the configure step when the GenMC commit changed.
205160
.out_dir(genmc_build_dir)
206161
.profile(GENMC_CMAKE_PROFILE)
162+
.define("BUILD_LLI", "OFF")
207163
.define("GENMC_DEBUG", if enable_genmc_debug { "ON" } else { "OFF" });
208164

209165
// The actual compilation happens here:
@@ -214,19 +170,11 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
214170
println!("cargo::rustc-link-search=native={}", cmake_lib_dir.display());
215171
println!("cargo::rustc-link-lib=static={GENMC_MODEL_CHECKER}");
216172

217-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
218-
let config_file = genmc_install_dir.join("include").join("genmc").join("config.h");
219-
let (llvm_definitions, llvm_include_dirs) = link_to_llvm(&config_file);
220-
221173
// Part 2:
222174
// Compile the cxx_bridge (the link between the Rust and C++ code).
223175

224176
let genmc_include_dir = genmc_install_dir.join("include").join("genmc");
225177

226-
// FIXME(genmc,llvm): remove once LLVM dependency is removed.
227-
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
228-
let definitions = llvm_definitions.split(";");
229-
230178
// These are all the C++ files we need to compile, which needs to be updated if more C++ files are added to Miri.
231179
// We use absolute paths since relative paths can confuse IDEs when attempting to go-to-source on a path in a compiler error.
232180
let cpp_files_base_path = Path::new("cpp/src/");
@@ -244,16 +192,12 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
244192
if enable_genmc_debug {
245193
bridge.define("ENABLE_GENMC_DEBUG", None);
246194
}
247-
for definition in definitions {
248-
bridge.flag(definition);
249-
}
250195
bridge
251196
.opt_level(2)
252197
.debug(true) // Same settings that GenMC uses (default for cmake `RelWithDebInfo`)
253198
.warnings(false) // NOTE: enabling this produces a lot of warnings.
254199
.std("c++23")
255200
.include(genmc_include_dir)
256-
.include(llvm_include_dirs)
257201
.include("./cpp/include")
258202
.files(&cpp_files)
259203
.out_dir(interface_build_dir)

src/tools/miri/genmc-sys/cpp/include/ResultHandling.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// GenMC headers:
88
#include "Verification/VerificationError.hpp"
99

10+
#include <format>
11+
#include <memory>
12+
#include <sstream>
1013
#include <string>
1114

1215
/** Information about an error, formatted as a string to avoid having to share an error enum and
1316
* printing functionality with the Rust side. */
1417
static auto format_error(VerificationError err) -> std::unique_ptr<std::string> {
15-
auto buf = std::string();
16-
auto s = llvm::raw_string_ostream(buf);
17-
s << err;
18+
std::stringstream s;
19+
s << std::format("{}", err);
1820
return std::make_unique<std::string>(s.str());
1921
}
2022

0 commit comments

Comments
 (0)