mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-13 07:11:05 +00:00
@@ -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 }
|
||||
@@ -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");
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
extern "C" {
|
||||
pub fn LLDELFLink(args: *const *const libc::c_char, size: libc::size_t) -> libc::c_int;
|
||||
}
|
||||
@@ -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(); });
|
||||
}
|
||||
Reference in New Issue
Block a user