custom ir

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
Cyrill Leutwiler
2024-02-02 09:10:03 +01:00
parent 7a094f17c0
commit d238d8f39e
48 changed files with 4399 additions and 603 deletions
+15 -13
View File
@@ -1,25 +1,27 @@
// SPDX-License-Identifier: Apache-2.0
fn llvm_config(arg: &str) -> String {
let output = std::process::Command::new("llvm-config")
.args([arg])
.output()
.unwrap_or_else(|_| panic!("`llvm-config {arg}` failed"));
use std::{io::Read, process::Command};
String::from_utf8(output.stdout)
.unwrap_or_else(|_| panic!("output of `llvm-config {arg}` should be utf8"))
}
fn main() {
let mut flags = String::new();
Command::new("llvm-config")
.args(["--cxxflags"])
.output()
.expect("llvm-config should be able to provide CXX flags")
.stdout
.as_slice()
.read_to_string(&mut flags)
.expect("llvm-config output should be utf8");
let mut builder = cc::Build::new();
flags
llvm_config("--cxxflags")
.split_whitespace()
.fold(&mut builder, |builder, flag| builder.flag(flag))
.cpp(true)
.file("src/linker.cpp")
.compile("liblinker.a");
println!("cargo:rustc-link-search=native={}", llvm_config("--libdir"));
for lib in ["lldELF", "lldCommon", "lldMachO"] {
println!("cargo:rustc-link-lib=static={lib}");
}
println!("cargo:rerun-if-changed=build.rs");
}
+1 -3
View File
@@ -1,5 +1,3 @@
// SPDX-License-Identifier: Apache-2.0
#include "lld/Common/Driver.h"
#include "lld/Common/CommonLinkerContext.h"
#include "llvm/Support/CrashRecoveryContext.h"
@@ -19,4 +17,4 @@ extern "C" bool LLDELFLink(const char *argv[], size_t length)
llvm::CrashRecoveryContext crc;
return canRunAgain && crc.RunSafely([&]()
{ lld::CommonLinkerContext::destroy(); });
}
}