Skip to content

Commit

Permalink
Improve compilation error on 32-bit (#2424)
Browse files Browse the repository at this point in the history
## Issue Addressed

Closes #1661

## Proposed Changes

Add a dummy package called `target_check` which gets compiled early in the build and fails if the target is 32-bit

## Additional Info

You can test the efficacy of this check with:

```
cross build --release --manifest-path lighthouse/Cargo.toml --target i686-unknown-linux-gnu
```

In which case this compilation error is shown:

```
error: Lighthouse requires a 64-bit CPU and operating system
  --> common/target_check/src/lib.rs:8:1
   |
8  | / assert_cfg!(
9  | |     target_pointer_width = "64",
10 | |     "Lighthouse requires a 64-bit CPU and operating system",
11 | | );
   | |__^
```
  • Loading branch information
michaelsproul committed Jun 30, 2021
1 parent 9461ac2 commit 379664a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ members = [
"common/sensitive_url",
"common/slot_clock",
"common/task_executor",
"common/target_check",
"common/test_random_derive",
"common/validator_dir",
"common/warp_utils",
Expand Down
8 changes: 8 additions & 0 deletions common/target_check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "target_check"
version = "0.1.0"
authors = ["Michael Sproul <[email protected]>"]
edition = "2018"

[dependencies]
static_assertions = "1.1.0"
11 changes: 11 additions & 0 deletions common/target_check/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! This crate checks properties of the target architecture to ensure that it's compatible with
//! Lighthouse.
use static_assertions::assert_cfg;

// In many places we assume `usize` and `u64` have the same in-memory representation.
// We also use memory-mapped files extensively which are only really viable with 64-bit addressing.
// It's unlikely we will want to support 128-bit architectures any time soon.
assert_cfg!(
target_pointer_width = "64",
"Lighthouse requires a 64-bit CPU and operating system",
);
6 changes: 6 additions & 0 deletions lighthouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ lazy_static = "1.4.0"
serde_json = "1.0.59"
task_executor = { path = "../common/task_executor" }
malloc_utils = { path = "../common/malloc_utils" }
target_check = { path = "../common/target_check" }

[dev-dependencies]
tempfile = "3.1.0"
Expand All @@ -57,3 +58,8 @@ eth2_libp2p = { path = "../beacon_node/eth2_libp2p" }
[[test]]
name = "lighthouse_tests"
path = "tests/main.rs"

# Prevent cargo-udeps from flagging the dummy package `target_check`, which exists only
# to assert properties of the compilation target.
[package.metadata.cargo-udeps.ignore]
normal = ["target_check"]

0 comments on commit 379664a

Please sign in to comment.