add more crates

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2023-12-09 17:48:52 +01:00
parent c04ae9a5c3
commit 7a094f17c0
22 changed files with 191 additions and 34 deletions
+14
View File
@@ -0,0 +1,14 @@
[package]
name = "lld-sys"
version = "0.1.0"
edition = "2021"
build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libc = { workspace = true }
[build-dependencies]
cc = { workspace = true }
+25
View File
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: Apache-2.0
use std::{io::Read, process::Command};
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
.split_whitespace()
.fold(&mut builder, |builder, flag| builder.flag(flag))
.cpp(true)
.file("src/linker.cpp")
.compile("liblinker.a");
println!("cargo:rerun-if-changed=build.rs");
}
+3
View File
@@ -0,0 +1,3 @@
extern "C" {
pub fn LLDELFLink(args: *const *const libc::c_char, size: libc::size_t) -> libc::c_int;
}
+22
View File
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
#include "lld/Common/Driver.h"
#include "lld/Common/CommonLinkerContext.h"
#include "llvm/Support/CrashRecoveryContext.h"
extern "C" bool LLDELFLink(const char *argv[], size_t length)
{
bool canRunAgain;
{
llvm::ArrayRef<const char *> args(argv, length);
llvm::CrashRecoveryContext crc;
if (!crc.RunSafely([&]()
{ canRunAgain = lld::elf::link(args, llvm::outs(), llvm::errs(), false, false); }))
return false;
}
llvm::CrashRecoveryContext crc;
return canRunAgain && crc.RunSafely([&]()
{ lld::CommonLinkerContext::destroy(); });
}