mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-12-01 23:07:12 +00:00
Update LLVM from 21 to 22 (#505)
This commit is contained in:
1 parent
72d47e4d26
commit
8326aa3aed
49 files changed
+182
-181
No files matched your search
@@ -1,7 +1,7 @@
|
||||
//! The compiler build utilities library.
|
||||
|
||||
/// The revive LLVM host dependency directory prefix environment variable.
|
||||
pub const REVIVE_LLVM_HOST_PREFIX: &str = "LLVM_SYS_211_PREFIX";
|
||||
pub const REVIVE_LLVM_HOST_PREFIX: &str = "LLVM_SYS_221_PREFIX";
|
||||
|
||||
/// The revive LLVM target dependency directory prefix environment variable.
|
||||
pub const REVIVE_LLVM_TARGET_PREFIX: &str = "REVIVE_LLVM_TARGET_PREFIX";
|
||||
|
||||
+16
-20
@@ -1,4 +1,7 @@
|
||||
use std::{env, fs, io::Read, path::Path, process::Command};
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
||||
|
||||
@@ -7,28 +10,21 @@ fn main() {
|
||||
"cargo:rerun-if-env-changed={}",
|
||||
revive_build_utils::REVIVE_LLVM_HOST_PREFIX
|
||||
);
|
||||
println!(
|
||||
"cargo:rerun-if-env-changed={}",
|
||||
revive_build_utils::REVIVE_LLVM_TARGET_PREFIX
|
||||
);
|
||||
|
||||
let llvm_config = revive_build_utils::llvm_host_tool("llvm-config");
|
||||
let mut llvm_lib_dir = String::new();
|
||||
Command::new(&llvm_config)
|
||||
.arg("--libdir")
|
||||
.output()
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"{} should be able to provide LD path",
|
||||
llvm_config.display()
|
||||
)
|
||||
})
|
||||
.stdout
|
||||
.as_slice()
|
||||
.read_to_string(&mut llvm_lib_dir)
|
||||
.expect("llvm-config output should be utf8");
|
||||
// When cross-compiling, the riscv64 builtins live in the target LLVM,
|
||||
// not the host LLVM that `LLVM_SYS_221_PREFIX` points at.
|
||||
let llvm_lib_dir = match env::var_os(revive_build_utils::REVIVE_LLVM_TARGET_PREFIX) {
|
||||
Some(prefix) => PathBuf::from(prefix).join("lib"),
|
||||
None => revive_build_utils::llvm_lib_dir(),
|
||||
};
|
||||
|
||||
let lib_path = revive_build_utils::llvm_lib_dir()
|
||||
.join("unknown")
|
||||
.join(BUILTINS_ARCHIVE_FILE);
|
||||
let lib_path = llvm_lib_dir.join("unknown").join(BUILTINS_ARCHIVE_FILE);
|
||||
let archive = fs::read(&lib_path).expect("clang builtins not found");
|
||||
println!("cargo:rerun-if-env-changed={}", lib_path.display());
|
||||
println!("cargo:rerun-if-changed={}", lib_path.display());
|
||||
|
||||
let out_dir = env::var_os("OUT_DIR").expect("has OUT_DIR");
|
||||
let archive_path = Path::new(&out_dir).join(BUILTINS_ARCHIVE_FILE);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"Baseline": 870,
|
||||
"Computation": 2418,
|
||||
"DivisionArithmetics": 9404,
|
||||
"ERC20": 17160,
|
||||
"DivisionArithmetics": 9274,
|
||||
"ERC20": 17090,
|
||||
"Events": 1662,
|
||||
"FibonacciIterative": 1427,
|
||||
"Flipper": 2240,
|
||||
"SHA1": 8009
|
||||
"SHA1": 8056
|
||||
}
|
||||
+11
-2
@@ -9,6 +9,8 @@ fn set_rustc_link_flags() {
|
||||
llvm_lib_path.to_string_lossy()
|
||||
);
|
||||
|
||||
let llvm_built_with_libcxx = llvm_lib_path.join("libc++.a").exists();
|
||||
|
||||
for lib in [
|
||||
// These are required by ld.lld
|
||||
"lldELF",
|
||||
@@ -96,15 +98,22 @@ fn set_rustc_link_flags() {
|
||||
"LLVMVectorize",
|
||||
"LLVMSandboxIR",
|
||||
"LLVMExtensions",
|
||||
"LLVMDTLTO",
|
||||
"LLVMPlugins",
|
||||
"LLVMFrontendHLSL",
|
||||
] {
|
||||
println!("cargo:rustc-link-lib=static={lib}");
|
||||
}
|
||||
|
||||
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
||||
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
|
||||
if target_os == "linux" {
|
||||
if target_env == "musl" {
|
||||
if llvm_built_with_libcxx {
|
||||
// LLVM archives reference `std::__1::…` and unwinder symbols that
|
||||
// `libstdc++` does not provide; pull them from the LLVM prefix.
|
||||
println!("cargo:rustc-link-lib=static=c++");
|
||||
if llvm_lib_path.join("libunwind.a").exists() {
|
||||
println!("cargo:rustc-link-lib=static=unwind");
|
||||
}
|
||||
} else {
|
||||
println!("cargo:rustc-link-lib=dylib=stdc++");
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ Obtain a compatible build for your host platform from the release section of thi
|
||||
|
||||
Build artifacts end up in the `./target-llvm/gnu/target-final/` directory by default.
|
||||
The `gnu` directory depends on the supported archticture and will either be `gnu`, `musl` or `emscripten`.
|
||||
You now need to export the final target directory `$LLVM_SYS_211_PREFIX`:
|
||||
You now need to export the final target directory `$LLVM_SYS_221_PREFIX`:
|
||||
|
||||
```shell
|
||||
export LLVM_SYS_211_PREFIX=${PWD}/target-llvm/gnu/target-final
|
||||
export LLVM_SYS_221_PREFIX=${PWD}/target-llvm/gnu/target-final
|
||||
```
|
||||
|
||||
If built with the `--enable-tests` option, test tools will be in the `./target-llvm/gnu/build-final/` directory, along with copies of the build artifacts. For all supported build options, run `revive-llvm build --help`.
|
||||
|
||||
@@ -77,7 +77,6 @@ pub fn build(
|
||||
llvm_module_llvm.as_path(),
|
||||
llvm_build_final.as_path(),
|
||||
llvm_target_final.as_path(),
|
||||
musl_target.as_path(),
|
||||
llvm_target_host.as_path(),
|
||||
enable_tests,
|
||||
enable_coverage,
|
||||
@@ -269,7 +268,6 @@ fn build_target(
|
||||
source_directory: &Path,
|
||||
build_directory: &Path,
|
||||
target_directory: &Path,
|
||||
musl_target_directory: &Path,
|
||||
host_target_directory: &Path,
|
||||
enable_tests: bool,
|
||||
enable_coverage: bool,
|
||||
@@ -366,26 +364,21 @@ fn build_target(
|
||||
|
||||
crate::utils::ninja(build_directory)?;
|
||||
|
||||
let mut musl_lib_directory = musl_target_directory.to_path_buf();
|
||||
musl_lib_directory.push("lib/");
|
||||
|
||||
let mut host_lib_directory = host_target_directory.to_path_buf();
|
||||
host_lib_directory.push("lib/aarch64-unknown-linux-musl/");
|
||||
|
||||
let mut target_lib_directory = target_directory.to_path_buf();
|
||||
target_lib_directory.push("lib/");
|
||||
|
||||
// Stage libc++/libunwind alongside the LLVM archives so `LLVM_SYS_221_PREFIX`
|
||||
// consumers can resolve the libc++ symbols they reference. The musl sysroot
|
||||
// is not copied: it would shadow the host libc on the link search path.
|
||||
let copy_options = fs_extra::dir::CopyOptions {
|
||||
overwrite: true,
|
||||
copy_inside: true,
|
||||
content_only: true,
|
||||
..Default::default()
|
||||
};
|
||||
fs_extra::dir::copy(
|
||||
musl_lib_directory,
|
||||
target_lib_directory.as_path(),
|
||||
©_options,
|
||||
)?;
|
||||
fs_extra::dir::copy(
|
||||
host_lib_directory,
|
||||
target_lib_directory.as_path(),
|
||||
|
||||
@@ -80,7 +80,6 @@ pub fn build(
|
||||
llvm_module_llvm.as_path(),
|
||||
llvm_build_final.as_path(),
|
||||
llvm_target_final.as_path(),
|
||||
musl_target.as_path(),
|
||||
llvm_target_host.as_path(),
|
||||
enable_tests,
|
||||
enable_coverage,
|
||||
@@ -267,7 +266,6 @@ fn build_target(
|
||||
source_directory: &Path,
|
||||
build_directory: &Path,
|
||||
target_directory: &Path,
|
||||
musl_target_directory: &Path,
|
||||
host_target_directory: &Path,
|
||||
enable_tests: bool,
|
||||
enable_coverage: bool,
|
||||
@@ -366,26 +364,21 @@ fn build_target(
|
||||
|
||||
crate::utils::ninja(build_directory)?;
|
||||
|
||||
let mut musl_lib_directory = musl_target_directory.to_path_buf();
|
||||
musl_lib_directory.push("lib/");
|
||||
|
||||
let mut host_lib_directory = host_target_directory.to_path_buf();
|
||||
host_lib_directory.push("lib/x86_64-pc-linux-musl/");
|
||||
|
||||
let mut target_lib_directory = target_directory.to_path_buf();
|
||||
target_lib_directory.push("lib/");
|
||||
|
||||
// Stage libc++/libunwind alongside the LLVM archives so `LLVM_SYS_221_PREFIX`
|
||||
// consumers can resolve the libc++ symbols they reference. The musl sysroot
|
||||
// is not copied: it would shadow the host libc on the link search path.
|
||||
let copy_options = fs_extra::dir::CopyOptions {
|
||||
overwrite: true,
|
||||
copy_inside: true,
|
||||
content_only: true,
|
||||
..Default::default()
|
||||
};
|
||||
fs_extra::dir::copy(
|
||||
musl_lib_directory,
|
||||
target_lib_directory.as_path(),
|
||||
©_options,
|
||||
)?;
|
||||
fs_extra::dir::copy(
|
||||
host_lib_directory,
|
||||
target_lib_directory.as_path(),
|
||||
|
||||
@@ -7,9 +7,14 @@ use std::str::FromStr;
|
||||
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
use revive_llvm_builder::target_env::TargetEnv;
|
||||
|
||||
use self::arguments::{Arguments, Subcommand};
|
||||
|
||||
/// RUSTFLAGS required when operating in a musl target environment so that the
|
||||
/// C runtime is linked dynamically rather than statically.
|
||||
const MUSL_RUSTFLAGS: &str = "-Ctarget-feature=-crt-static";
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
@@ -25,6 +30,10 @@ fn main() {
|
||||
fn main_inner() -> anyhow::Result<()> {
|
||||
let arguments = Arguments::parse();
|
||||
|
||||
if arguments.target_env == TargetEnv::MUSL {
|
||||
std::env::set_var("RUSTFLAGS", MUSL_RUSTFLAGS);
|
||||
}
|
||||
|
||||
revive_llvm_builder::utils::directory_target_llvm(arguments.target_env);
|
||||
|
||||
match arguments.subcommand {
|
||||
|
||||
@@ -35,88 +35,90 @@ pub enum Attribute {
|
||||
NoBuiltin = 24,
|
||||
NoCallback = 25,
|
||||
NoCfCheck = 26,
|
||||
NoDivergenceSource = 27,
|
||||
NoDuplicate = 28,
|
||||
NoExt = 29,
|
||||
NoFree = 30,
|
||||
NoImplicitFloat = 31,
|
||||
NoInline = 32,
|
||||
NoMerge = 33,
|
||||
NoProfile = 34,
|
||||
NoRecurse = 35,
|
||||
NoRedZone = 36,
|
||||
NoReturn = 37,
|
||||
NoSanitizeBounds = 38,
|
||||
NoSanitizeCoverage = 39,
|
||||
NoSync = 40,
|
||||
NoUndef = 41,
|
||||
NoUnwind = 42,
|
||||
NonLazyBind = 43,
|
||||
NonNull = 44,
|
||||
NullPointerIsValid = 45,
|
||||
OptForFuzzing = 46,
|
||||
OptimizeForDebugging = 47,
|
||||
OptimizeForSize = 48,
|
||||
OptimizeNone = 49,
|
||||
PresplitCoroutine = 50,
|
||||
ReadNone = 51,
|
||||
ReadOnly = 52,
|
||||
Returned = 53,
|
||||
ReturnsTwice = 54,
|
||||
SExt = 55,
|
||||
SafeStack = 56,
|
||||
SanitizeAddress = 57,
|
||||
SanitizeHWAddress = 58,
|
||||
SanitizeMemTag = 59,
|
||||
SanitizeMemory = 60,
|
||||
SanitizeNumericalStability = 61,
|
||||
SanitizeRealtime = 62,
|
||||
SanitizeRealtimeBlocking = 63,
|
||||
SanitizeThread = 64,
|
||||
SanitizeType = 65,
|
||||
ShadowCallStack = 66,
|
||||
SkipProfile = 67,
|
||||
Speculatable = 68,
|
||||
SpeculativeLoadHardening = 69,
|
||||
StackProtect = 70,
|
||||
StackProtectReq = 71,
|
||||
StackProtectStrong = 72,
|
||||
StrictFP = 73,
|
||||
SwiftAsync = 74,
|
||||
SwiftError = 75,
|
||||
SwiftSelf = 76,
|
||||
WillReturn = 77,
|
||||
Writable = 78,
|
||||
WriteOnly = 79,
|
||||
ZExt = 80,
|
||||
//LastEnumAttr = 80,
|
||||
//FirstTypeAttr = 81,
|
||||
ByRef = 81,
|
||||
ByVal = 82,
|
||||
ElementType = 83,
|
||||
InAlloca = 84,
|
||||
Preallocated = 85,
|
||||
StructRet = 86,
|
||||
//LastTypeAttr = 86,
|
||||
//FirstIntAttr = 87,
|
||||
Alignment = 87,
|
||||
AllocKind = 88,
|
||||
AllocSize = 89,
|
||||
Captures = 90,
|
||||
Dereferenceable = 91,
|
||||
DereferenceableOrNull = 92,
|
||||
Memory = 93,
|
||||
NoFPClass = 94,
|
||||
StackAlignment = 95,
|
||||
UWTable = 96,
|
||||
VScaleRange = 97,
|
||||
//LastIntAttr = 97,
|
||||
//FirstConstantRangeAttr = 98,
|
||||
Range = 98,
|
||||
//LastConstantRangeAttr = 98,
|
||||
//FirstConstantRangeListAttr = 99,
|
||||
Initializes = 99,
|
||||
//LastConstantRangeListAttr = 99,
|
||||
NoCreateUndefOrPoison = 27,
|
||||
NoDivergenceSource = 28,
|
||||
NoDuplicate = 29,
|
||||
NoExt = 30,
|
||||
NoFree = 31,
|
||||
NoImplicitFloat = 32,
|
||||
NoInline = 33,
|
||||
NoMerge = 34,
|
||||
NoProfile = 35,
|
||||
NoRecurse = 36,
|
||||
NoRedZone = 37,
|
||||
NoReturn = 38,
|
||||
NoSanitizeBounds = 39,
|
||||
NoSanitizeCoverage = 40,
|
||||
NoSync = 41,
|
||||
NoUndef = 42,
|
||||
NoUnwind = 43,
|
||||
NonLazyBind = 44,
|
||||
NonNull = 45,
|
||||
NullPointerIsValid = 46,
|
||||
OptForFuzzing = 47,
|
||||
OptimizeForDebugging = 48,
|
||||
OptimizeForSize = 49,
|
||||
OptimizeNone = 50,
|
||||
PresplitCoroutine = 51,
|
||||
ReadNone = 52,
|
||||
ReadOnly = 53,
|
||||
Returned = 54,
|
||||
ReturnsTwice = 55,
|
||||
SExt = 56,
|
||||
SafeStack = 57,
|
||||
SanitizeAddress = 58,
|
||||
SanitizeAllocToken = 59,
|
||||
SanitizeHWAddress = 60,
|
||||
SanitizeMemTag = 61,
|
||||
SanitizeMemory = 62,
|
||||
SanitizeNumericalStability = 63,
|
||||
SanitizeRealtime = 64,
|
||||
SanitizeRealtimeBlocking = 65,
|
||||
SanitizeThread = 66,
|
||||
SanitizeType = 67,
|
||||
ShadowCallStack = 68,
|
||||
SkipProfile = 69,
|
||||
Speculatable = 70,
|
||||
SpeculativeLoadHardening = 71,
|
||||
StackProtect = 72,
|
||||
StackProtectReq = 73,
|
||||
StackProtectStrong = 74,
|
||||
StrictFP = 75,
|
||||
SwiftAsync = 76,
|
||||
SwiftError = 77,
|
||||
SwiftSelf = 78,
|
||||
WillReturn = 79,
|
||||
Writable = 80,
|
||||
WriteOnly = 81,
|
||||
ZExt = 82,
|
||||
//LastEnumAttr = 82,
|
||||
//FirstTypeAttr = 83,
|
||||
ByRef = 83,
|
||||
ByVal = 84,
|
||||
ElementType = 85,
|
||||
InAlloca = 86,
|
||||
Preallocated = 87,
|
||||
StructRet = 88,
|
||||
//LastTypeAttr = 88,
|
||||
//FirstIntAttr = 89,
|
||||
Alignment = 89,
|
||||
AllocKind = 90,
|
||||
AllocSize = 91,
|
||||
Captures = 92,
|
||||
Dereferenceable = 93,
|
||||
DereferenceableOrNull = 94,
|
||||
Memory = 95,
|
||||
NoFPClass = 96,
|
||||
StackAlignment = 97,
|
||||
UWTable = 98,
|
||||
VScaleRange = 99,
|
||||
//LastIntAttr = 99,
|
||||
//FirstConstantRangeAttr = 100,
|
||||
Range = 100,
|
||||
//LastConstantRangeAttr = 100,
|
||||
//FirstConstantRangeListAttr = 101,
|
||||
Initializes = 101,
|
||||
//LastConstantRangeListAttr = 101,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Attribute {
|
||||
|
||||
@@ -287,7 +287,6 @@ impl<'ctx> Context<'ctx> {
|
||||
) -> anyhow::Result<Build> {
|
||||
self.link_polkavm_exports(contract_path)?;
|
||||
self.link_immutable_data(contract_path)?;
|
||||
|
||||
let target_machine = TargetMachine::new(Target::PVM, self.optimizer.settings())?;
|
||||
self.module().set_triple(&target_machine.get_triple());
|
||||
|
||||
|
||||
@@ -59,10 +59,10 @@ impl TargetMachine {
|
||||
}
|
||||
|
||||
/// Writes the LLVM module to a memory buffer.
|
||||
pub fn write_to_memory_buffer<'ctx>(
|
||||
pub fn write_to_memory_buffer(
|
||||
&self,
|
||||
module: &inkwell::module::Module<'ctx>,
|
||||
) -> Result<inkwell::memory_buffer::MemoryBuffer<'ctx>, inkwell::support::LLVMString> {
|
||||
module: &inkwell::module::Module,
|
||||
) -> Result<inkwell::memory_buffer::MemoryBuffer<'static>, inkwell::support::LLVMString> {
|
||||
match self.target {
|
||||
Target::PVM => self
|
||||
.target_machine
|
||||
|
||||
@@ -41,7 +41,7 @@ mimalloc = { version = "0.1.46", default-features = false }
|
||||
|
||||
[target.'cfg(target_os = "emscripten")'.dependencies]
|
||||
libc = { workspace = true }
|
||||
inkwell = { workspace = true, features = ["target-riscv", "llvm21-1-no-llvm-linking"]}
|
||||
inkwell = { workspace = true, features = ["target-riscv", "llvm22-1-no-llvm-linking"]}
|
||||
|
||||
[build-dependencies]
|
||||
git2 = { workspace = true, default-features = false }
|
||||
|
||||
@@ -9,7 +9,7 @@ description = "Implements the low level runtime API bindings with pallet contrac
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm21-1"] }
|
||||
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm22-1"] }
|
||||
|
||||
revive-common = { workspace = true }
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ repository.workspace = true
|
||||
description = "revive compiler stdlib components"
|
||||
|
||||
[dependencies]
|
||||
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm21-1"] }
|
||||
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm22-1"] }
|
||||
|
||||
[build-dependencies]
|
||||
revive-build-utils = { workspace = true }
|
||||
Reference in new issue
Block a user