Improve compilation error on 32-bit (#2424)

## 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 | | );
   | |__^
```
This commit is contained in:
Michael Sproul 2021-06-30 04:56:22 +00:00
parent 9461ac2d50
commit 379664a648
5 changed files with 36 additions and 0 deletions

10
Cargo.lock generated
View File

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3
[[package]] [[package]]
name = "account_manager" name = "account_manager"
version = "0.3.5" version = "0.3.5"
@ -3756,6 +3758,7 @@ dependencies = [
"slog-async", "slog-async",
"slog-term", "slog-term",
"sloggers", "sloggers",
"target_check",
"task_executor", "task_executor",
"tempfile", "tempfile",
"tokio 1.5.0", "tokio 1.5.0",
@ -6331,6 +6334,13 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "target_check"
version = "0.1.0"
dependencies = [
"static_assertions",
]
[[package]] [[package]]
name = "target_info" name = "target_info"
version = "0.1.0" version = "0.1.0"

View File

@ -37,6 +37,7 @@ members = [
"common/sensitive_url", "common/sensitive_url",
"common/slot_clock", "common/slot_clock",
"common/task_executor", "common/task_executor",
"common/target_check",
"common/test_random_derive", "common/test_random_derive",
"common/validator_dir", "common/validator_dir",
"common/warp_utils", "common/warp_utils",

View File

@ -0,0 +1,8 @@
[package]
name = "target_check"
version = "0.1.0"
authors = ["Michael Sproul <michael@sigmaprime.io>"]
edition = "2018"
[dependencies]
static_assertions = "1.1.0"

View File

@ -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",
);

View File

@ -47,6 +47,7 @@ lazy_static = "1.4.0"
serde_json = "1.0.59" serde_json = "1.0.59"
task_executor = { path = "../common/task_executor" } task_executor = { path = "../common/task_executor" }
malloc_utils = { path = "../common/malloc_utils" } malloc_utils = { path = "../common/malloc_utils" }
target_check = { path = "../common/target_check" }
[dev-dependencies] [dev-dependencies]
tempfile = "3.1.0" tempfile = "3.1.0"
@ -57,3 +58,8 @@ eth2_libp2p = { path = "../beacon_node/eth2_libp2p" }
[[test]] [[test]]
name = "lighthouse_tests" name = "lighthouse_tests"
path = "tests/main.rs" 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"]