Skip to content

Commit

Permalink
build.rs: Replace llvm-tools with cargo-binutils
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Dec 5, 2021
1 parent 3056caf commit 81322df
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/kvm_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
runs-on: [self-hosted]

steps:
- name: Install cargo-binutils
run: cargo install cargo-binutils
- uses: actions/checkout@v2
with:
submodules: true
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Install cargo-binutils
run: cargo install cargo-binutils
- uses: actions/checkout@v2
with:
submodules: true
Expand Down
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN apt-get update && \
# Install Rust toolchain
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly --profile minimal
RUN /root/.cargo/bin/cargo install cargo-download
RUN /root/.cargo/bin/cargo install cargo-binutils

ENV PATH="/root/.cargo/bin:/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/:${PATH}"
ENV EDITOR=vim
Expand Down
1 change: 0 additions & 1 deletion hermit-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ smp = []
[build-dependencies]
walkdir = "2"
target_build_utils = "0.3"
llvm-tools = { version = "0.1" }

[dependencies]
log = { version = "0.4", default-features = false }
Expand Down
29 changes: 3 additions & 26 deletions hermit-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate llvm_tools;
extern crate target_build_utils;
extern crate walkdir;

Expand All @@ -8,7 +7,6 @@ use std::ffi::OsString;
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process;
use std::process::Command;
use target_build_utils::TargetInfo;
use walkdir::{DirEntry, WalkDir};
Expand Down Expand Up @@ -174,36 +172,15 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
/// In addition, it provides us the offer to create a optimized version of memcpy
/// in user space.
fn rename_symbol(symbol: impl AsRef<OsStr>, lib: impl AsRef<Path>) {
// Get access to llvm tools shipped in the llvm-tools-preview rustup component
let llvm_tools = match llvm_tools::LlvmTools::new() {
Ok(tools) => tools,
Err(llvm_tools::Error::NotFound) => {
eprintln!("Error: llvm-tools not found");
eprintln!("Maybe the rustup component `llvm-tools-preview` is missing?");
eprintln!(" Install it through: `rustup component add llvm-tools-preview`");
process::exit(1);
}
Err(err) => {
eprintln!("Failed to retrieve llvm-tools component: {:?}", err);
process::exit(1);
}
};

// Retrieve path of llvm-objcopy
let llvm_objcopy = llvm_tools
.tool(&llvm_tools::exe("llvm-objcopy"))
.expect("llvm-objcopy not found in llvm-tools");

// Rename symbols
let arg = IntoIterator::into_iter([symbol.as_ref(), "=kernel-".as_ref(), symbol.as_ref()])
.collect::<OsString>();
let status = Command::new(llvm_objcopy)
let status = Command::new("rust-objcopy")
.arg("--redefine-sym")
.arg(arg)
.arg(lib.as_ref())
.status()
.expect("failed to execute llvm-objcopy");
assert!(status.success(), "llvm-objcopy was not successful");
.expect("Failed to execute rust-objcopy. Is cargo-binutils installed?");
assert!(status.success(), "rust-objcopy was not successful");
}

#[cfg(all(not(feature = "rustc-dep-of-std"), not(feature = "with_submodule")))]
Expand Down

0 comments on commit 81322df

Please sign in to comment.