Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #159 from anton-rs/cl/bin-split
Browse files Browse the repository at this point in the history
feat: Split binaries
  • Loading branch information
refcell authored Nov 5, 2023
2 parents af6d37b + 7482db8 commit ec97477
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ jobs:
name: clippy
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
include:
- binary: "reth"
network: "ethereum"
- binary: "op-reth"
network: "optimism"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@clippy
Expand All @@ -22,7 +29,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo clippy --workspace --all-targets --all-features
- run: cargo clippy --bin "${{ matrix.binary }}" --workspace --features "jemalloc,${{ matrix.network }}"
env:
RUSTFLAGS: -D warnings

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ env:
jobs:
unused-dependencies:
runs-on: ubuntu-latest
strategy:
matrix:
network: ["ethereum", "optimism"]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: taiki-e/install-action@cargo-udeps
- name: Check for unused dependencies
run: cargo udeps --all-features --all-targets
run: cargo udeps --features "jemalloc,${{ matrix.network }}"
- uses: JasonEtco/create-an-issue@v2
if: ${{ failure() }}
env:
Expand Down
27 changes: 26 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ install: ## Build and install the reth binary under `~/.cargo/bin`.
--profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS)

.PHONY: install-op
install-op: ## Build and install the op-reth binary under `~/.cargo/bin`.
cargo install --path bin/reth --bin op-reth --force --locked \
--features "optimism,$(FEATURES)" \
--profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS)

# Builds the reth binary natively.
build-native-%:
cargo build --bin reth --target $* --features "$(FEATURES)" --profile "$(PROFILE)"

op-build-native-%:
cargo build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)"

# The following commands use `cross` to build a cross-compile.
#
# These commands require that:
Expand All @@ -70,6 +80,10 @@ build-%:
RUSTFLAGS="-C link-arg=-lgcc -Clink-arg=-static-libgcc" \
cross build --bin reth --target $* --features "$(FEATURES)" --profile "$(PROFILE)"

op-build-%:
RUSTFLAGS="-C link-arg=-lgcc -Clink-arg=-static-libgcc" \
cross build --bin op-reth --target $* --features "optimism,$(FEATURES)" --profile "$(PROFILE)"

# Unfortunately we can't easily use cross to build for Darwin because of licensing issues.
# If we wanted to, we would need to build a custom Docker image with the SDK available.
#
Expand Down Expand Up @@ -105,19 +119,30 @@ build-release-tarballs: ## Create a series of `.tar.gz` files in the BIN_DIR dir

##@ Test

UNIT_TEST_ARGS := --locked --workspace --all-features -E 'kind(lib)' -E 'kind(bin)' -E 'kind(proc-macro)'
UNIT_TEST_ARGS := --locked --workspace --features 'jemalloc-prof' -E 'kind(lib)' -E 'kind(bin)' -E 'kind(proc-macro)'
UNIT_TEST_ARGS_OP := --locked --workspace --features 'jemalloc-prof,optimism' -E 'kind(lib)' -E 'kind(bin)' -E 'kind(proc-macro)'
COV_FILE := lcov.info

.PHONY: test-unit
test-unit: ## Run unit tests.
cargo install cargo-nextest --locked
cargo nextest run $(UNIT_TEST_ARGS)

.PHONY: test-unit-op
test-unit-op: ## Run unit tests (with optimism feature flag enabled).
cargo install cargo-nextest --locked
cargo nextest run $(UNIT_TEST_ARGS_OP)

.PHONY: cov-unit
cov-unit: ## Run unit tests with coverage.
rm -f $(COV_FILE)
cargo llvm-cov nextest --lcov --output-path $(COV_FILE) $(UNIT_TEST_ARGS)

.PHONY: cov-unit-op
cov-unit-op: ## Run unit tests with coverage (with optimism feature flag enabled).
rm -f $(COV_FILE)
cargo llvm-cov nextest --lcov --output-path $(COV_FILE) $(UNIT_TEST_ARGS_OP)

.PHONY: cov-report-html
cov-report-html: cov-unit ## Generate a HTML coverage report and open it in the browser.
cargo llvm-cov report --html
Expand Down
9 changes: 9 additions & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,12 @@ ethereum = []

[build-dependencies]
vergen = { version = "8.0.0", features = ["build", "cargo", "git", "gitcl"] }

[[bin]]
name = "reth"
path = "src/main.rs"

[[bin]]
name = "op-reth"
path = "src/optimism.rs"
required-features = ["optimism"]
4 changes: 4 additions & 0 deletions bin/reth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

#[cfg(feature = "optimism")]
compile_error!("Cannot build the `reth` binary with the `optimism` feature flag enabled. Did you mean to build `op-reth`?");

#[cfg(not(feature = "optimism"))]
fn main() {
if let Err(err) = reth::cli::run() {
eprintln!("Error: {err:?}");
Expand Down
15 changes: 15 additions & 0 deletions bin/reth/src/optimism.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// We use jemalloc for performance reasons
#[cfg(all(feature = "jemalloc", unix))]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

#[cfg(not(feature = "optimism"))]
compile_error!("Cannot build the `op-reth` binary with the `optimism` feature flag disabled. Did you mean to build `reth`?");

#[cfg(feature = "optimism")]
fn main() {
if let Err(err) = reth::cli::run() {
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}

0 comments on commit ec97477

Please sign in to comment.