Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README: document more building tricks #270

Merged
merged 6 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ jobs:
- name: Format
run: cargo fmt && git diff --exit-code
- name: Lint
run: |
rustup update
rustup component add clippy
cargo clippy
run: cargo clippy
- name: Cargo sort
run: |
cargo install cargo-sort
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ path = "src/lib.rs"
name = "siderophile"
path = "src/main.rs"

[build-dependencies]
version_check = "0.9"

[dependencies]
anyhow = "1"
cargo = "0.66.0"
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ Homebrew, you might do:
LLVM_SYS_150_PREFIX=$(brew --prefix)/opt/llvm@15/ cargo install siderophile
```

You _may_ run into other linker errors as well, e.g.:

```
= note: ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

You can fix this by setting the `LIBRARY_PATH`. For example, for macOS with
Homebrew:

```console
LIBRARY_PATH=$(brew --prefix)/lib cargo install siderophile
```

To tie it all together:

```console
LIBRARY_PATH=$(brew --prefix)/lib \
LLVM_SYS_150_PREFIX=$(brew --prefix)/opt/llvm@15/
cargo install siderophile
```

### Building and installing from source

Alternatively, if you'd like to build from source:
Expand All @@ -81,6 +103,9 @@ cargo build
cargo install --path .
```

You may need the same `LLVM_SYS_150_PATH` and `LIBRARY_PATH` overrides
mentioned above.

## How to use

Make sure that you followed the above steps, then do the following:
Expand Down
14 changes: 14 additions & 0 deletions build.rs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunate, but IMO produces a better user experience than our current one: the current UX is that cargo build or cargo install will complete successfully, but will fail to analyze any IR produced by versions of rustc newer than 1.67.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::process::exit;

use version_check::Version;

fn main() {
if !version_check::is_max_version("1.67.1").unwrap_or(false) {
eprintln!("Rust 1.68 and newer are not supported yet, as they require LLVM 16 or newer.");
eprintln!("You have: {}", Version::read().unwrap());
eprintln!(
"For more information, see https://github.com/trailofbits/siderophile/issues/267"
);
exit(1)
}
}
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.67"
profile = "default"
8 changes: 4 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ pub struct CallGraph {
#[allow(clippy::missing_panics_doc, clippy::expect_used, clippy::unwrap_used)]
pub fn configure_rustup_toolchain() {
let rsup_default = Command::new("rustup")
.arg("default")
.args(["show", "active-toolchain"])
.output()
.expect("failed to run rustup to configure toolchain");
let utf8_toolchain = std::str::from_utf8(&rsup_default.stdout)
Comment on lines 88 to 92
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now use rustup show active-toolchain to determine the toolchain to use. This should be slightly more reliable than rustup default, in the sense that it'll both respect user overrides and should (?) respect the local rust-toolchain.toml in any crate.

.unwrap()
.trim_end()
.strip_suffix(" (default)")
.unwrap();
.split_once(' ')
.unwrap()
.0;
env::set_var("RUSTUP_TOOLCHAIN", utf8_toolchain);

let rustc_version = rustc_version::version_meta().unwrap();
Expand Down