From 306a6d3c23e381fb238ff0114b7a2206272f2a73 Mon Sep 17 00:00:00 2001 From: cygaar Date: Sun, 14 Apr 2024 22:49:52 -0400 Subject: [PATCH 01/10] Add features flag for cargo stylus check/deploy --- src/check.rs | 1 + src/deploy.rs | 1 + src/main.rs | 3 +++ src/project.rs | 7 +++++++ 4 files changed, 12 insertions(+) diff --git a/src/check.rs b/src/check.rs index 9270e06..202f613 100644 --- a/src/check.rs +++ b/src/check.rs @@ -65,6 +65,7 @@ pub async fn run_checks(cfg: CheckConfig) -> eyre::Result { Some(path) => PathBuf::from_str(path).unwrap(), None => project::build_project_dylib(BuildConfig { opt_level: project::OptLevel::default(), + features: cfg.features.clone(), nightly: cfg.nightly, rebuild: true, skip_contract_size_check: cfg.skip_contract_size_check, diff --git a/src/deploy.rs b/src/deploy.rs index 9f68b63..4a3492f 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -116,6 +116,7 @@ programs to Stylus chains here https://docs.arbitrum.io/stylus/stylus-quickstart Some(path) => PathBuf::from_str(path).unwrap(), None => project::build_project_dylib(BuildConfig { opt_level: project::OptLevel::default(), + features: cfg.check_cfg.features, nightly: cfg.check_cfg.nightly, rebuild: false, // The check step at the start of this command rebuilt. skip_contract_size_check: cfg.check_cfg.skip_contract_size_check, diff --git a/src/main.rs b/src/main.rs index d92ea9c..44304ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,6 +95,9 @@ pub struct CheckConfig { /// Specifies a WASM file instead of looking for one in the current directory. #[arg(long)] wasm_file_path: Option, + /// Specifies the features to use when building the Stylus binary. + #[arg(long)] + features: Option, /// Specify the program address we want to check activation for. If unspecified, it will /// compute the next program address from the user's wallet address and nonce, which will require /// wallet-related flags to be specified. diff --git a/src/project.rs b/src/project.rs index 2188bf4..f22d544 100644 --- a/src/project.rs +++ b/src/project.rs @@ -21,6 +21,7 @@ pub enum OptLevel { pub struct BuildConfig { pub opt_level: OptLevel, + pub features: Option, pub nightly: bool, pub rebuild: bool, pub skip_contract_size_check: bool, @@ -65,6 +66,10 @@ pub fn build_project_dylib(cfg: BuildConfig) -> Result { cmd.arg("build"); cmd.arg("--lib"); + if cfg.features != None { + cmd.arg(format!("--features={}", cfg.features.clone().unwrap())); + } + if cfg.nightly { cmd.arg("-Z"); cmd.arg("build-std=std,panic_abort"); @@ -126,6 +131,7 @@ https://github.com/OffchainLabs/cargo-stylus/blob/main/OPTIMIZING_BINARIES.md"#, // Attempt to build again with a bumped-up optimization level. return build_project_dylib(BuildConfig { opt_level: OptLevel::Z, + features: cfg.features, nightly: cfg.nightly, rebuild: true, skip_contract_size_check: cfg.skip_contract_size_check, @@ -141,6 +147,7 @@ https://github.com/OffchainLabs/cargo-stylus/blob/main/OPTIMIZING_BINARIES.md"#, // only available with nightly compilation. return build_project_dylib(BuildConfig { opt_level: OptLevel::Z, + features: cfg.features, nightly: true, rebuild: true, skip_contract_size_check: cfg.skip_contract_size_check, From 90f7f320f27202560b3b44bc31c54dac1459c3ed Mon Sep 17 00:00:00 2001 From: bayge Date: Sat, 5 Oct 2024 17:48:46 +0930 Subject: [PATCH 02/10] merge --- install.sh | 5 +++++ main/src/main.rs | 25 +++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100755 install.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..05bf742 --- /dev/null +++ b/install.sh @@ -0,0 +1,5 @@ +#!/bin/sh -e + +cargo fmt +cargo clippy --package cargo-stylus --package cargo-stylus-example +cargo install --path main diff --git a/main/src/main.rs b/main/src/main.rs index acb510f..5cd0baa 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -258,6 +258,12 @@ struct ReplayArgs { /// Whether to use stable Rust. Note that nightly is needed to expand macros. #[arg(short, long)] stable_rust: bool, + /// Any features that should be passed to cargo build. + #[arg(short, long)] + features: Option>, + /// Which specific package to build during replay, if any. + #[arg(long)] + package: Option, /// Whether this process is the child of another. #[arg(short, long, hide(true))] child: bool, @@ -681,7 +687,7 @@ async fn replay(args: ReplayArgs) -> Result<()> { let provider = sys::new_provider(&args.trace.endpoint)?; let trace = Trace::new(provider, args.trace.tx, args.trace.use_native_tracer).await?; - build_shared_library(&args.trace.project)?; + build_shared_library(&args.trace.project, args.package, args.feature)?; let library_extension = if macos { ".dylib" } else { ".so" }; let shared_library = find_shared_library(&args.trace.project, library_extension)?; @@ -704,12 +710,23 @@ async fn replay(args: ReplayArgs) -> Result<()> { Ok(()) } -pub fn build_shared_library(path: &Path) -> Result<()> { +pub fn build_shared_library( + path: &Path, + package: Option, + features: Option>, +) -> Result<()> { let mut cargo = sys::new_command("cargo"); + cargo.current_dir(path).arg("build"); + + if let Some(f) = features { + cargo.arg("--features").arg(f.join(",")); + } + if let Some(p) = package { + cargo.arg("--package").arg(p); + } + cargo - .current_dir(path) - .arg("build") .arg("--lib") .arg("--locked") .arg("--target") From 92f891d291ed1468793e336627496c127ee88f58 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 12 Dec 2024 12:32:20 -0600 Subject: [PATCH 03/10] clone --- main/src/check.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/check.rs b/main/src/check.rs index 92c4863..b621cba 100644 --- a/main/src/check.rs +++ b/main/src/check.rs @@ -121,7 +121,7 @@ impl CheckConfig { let toolchain_channel = extract_toolchain_channel(&toolchain_file_path)?; let rust_stable = !toolchain_channel.contains("nightly"); let mut cfg = BuildConfig::new(rust_stable); - cfg.features = self.common_cfg.features; + cfg.features = self.common_cfg.features.clone(); let wasm = project::build_dylib(cfg.clone())?; let project_hash = project::hash_project(self.common_cfg.source_files_for_project_hash.clone(), cfg)?; From 48718d6873e0838a3436f58330862ce8a62ee238 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 12 Dec 2024 13:17:39 -0600 Subject: [PATCH 04/10] josh feedback --- Dockerfile | 16 ++++++++-------- Makefile | 29 ----------------------------- install.sh | 5 ----- rust-toolchain.toml | 2 ++ 4 files changed, 10 insertions(+), 42 deletions(-) delete mode 100644 Makefile delete mode 100755 install.sh create mode 100644 rust-toolchain.toml diff --git a/Dockerfile b/Dockerfile index 7143a4e..46ac634 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,15 @@ ARG BUILD_PLATFORM=linux/amd64 -ARG RUST_VERSION=1.80 -ARG CARGO_STYLUS_VERSION=0.5.6 - +ARG RUST_VERSION=1.83 FROM --platform=${BUILD_PLATFORM} rust:${RUST_VERSION} AS builder -RUN apt-get update && apt-get install -y git + RUN rustup target add x86_64-unknown-linux-gnu -ARG CARGO_STYLUS_VERSION -RUN test -n "$CARGO_STYLUS_VERSION" -RUN git clone --branch v$CARGO_STYLUS_VERSION https://github.com/offchainlabs/cargo-stylus.git + +# Copy the entire workspace +COPY . /cargo-stylus/ WORKDIR /cargo-stylus + +# Build the project using the workspace member RUN cargo build --release --manifest-path main/Cargo.toml FROM --platform=${BUILD_PLATFORM} rust:${RUST_VERSION} AS cargo-stylus-base -COPY --from=builder /cargo-stylus/target/release/cargo-stylus /usr/local/bin/cargo-stylus +COPY --from=builder /cargo-stylus/target/release/cargo-stylus /usr/local/bin/cargo-stylus \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 6b94b6d..0000000 --- a/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -CARGO_STYLUS_VERSION := $(shell cargo pkgid --manifest-path main/Cargo.toml | cut -d '@' -f 2) - -.PHONY: build -build: - cargo build - -.PHONY: test -test: - cargo test - -.PHONY: bench -bench: - cargo +nightly bench -F nightly - -.PHONY: fmt -fmt: - cargo fmt - -.PHONY: lint -lint: - cargo clippy --package cargo-stylus --package cargo-stylus-example - -.PHONY: install -install: fmt lint - cargo install --path main - -.PHONY: docker -docker: - docker build -t cargo-stylus-base:$(CARGO_STYLUS_VERSION) --build-arg CARGO_STYLUS_VERSION=$(CARGO_STYLUS_VERSION) . diff --git a/install.sh b/install.sh deleted file mode 100755 index 05bf742..0000000 --- a/install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -e - -cargo fmt -cargo clippy --package cargo-stylus --package cargo-stylus-example -cargo install --path main diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..0193dee --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.83.0" From be330226b84cccb57f870cc6c9ce77c4553e19ff Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 12 Dec 2024 13:22:48 -0600 Subject: [PATCH 05/10] edit marker --- main/src/main.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/main/src/main.rs b/main/src/main.rs index b8bf51e..d4c0c52 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -1,9 +1,6 @@ // Copyright 2023-2024, Offchain Labs, Inc. // For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md -// Enable unstable test feature for benchmarks when nightly is available -#![cfg_attr(feature = "nightly", feature(test))] - use alloy_primitives::TxHash; use clap::{ArgGroup, Args, CommandFactory, Parser, Subcommand}; use constants::DEFAULT_ENDPOINT; From 8724a7bd5edacf20ed48f2bc21386154902e27e7 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 12 Dec 2024 13:56:03 -0600 Subject: [PATCH 06/10] eol --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 46ac634..c6c02e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,4 @@ WORKDIR /cargo-stylus RUN cargo build --release --manifest-path main/Cargo.toml FROM --platform=${BUILD_PLATFORM} rust:${RUST_VERSION} AS cargo-stylus-base -COPY --from=builder /cargo-stylus/target/release/cargo-stylus /usr/local/bin/cargo-stylus \ No newline at end of file +COPY --from=builder /cargo-stylus/target/release/cargo-stylus /usr/local/bin/cargo-stylus From b994eeeff0011477c69d4d7428e8d82320cbbb95 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 12 Dec 2024 15:24:07 -0600 Subject: [PATCH 07/10] Update main/src/project.rs Co-authored-by: Gabriel de Quadros Ligneul <8294320+gligneul@users.noreply.github.com> --- main/src/project.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/src/project.rs b/main/src/project.rs index 33be8ad..8b4ef5e 100644 --- a/main/src/project.rs +++ b/main/src/project.rs @@ -75,8 +75,8 @@ pub fn build_dylib(cfg: BuildConfig) -> Result { cmd.arg("--lib"); cmd.arg("--locked"); - if cfg.features.is_some() { - cmd.arg(format!("--features={}", cfg.features.clone().unwrap())); + if let Some(features) = cfg.features { + cmd.arg(format!("--features={}", features.clone())); } if !cfg.stable { From 48f7c84bc73cec4dda92490d4023daf9770242a9 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 12 Dec 2024 15:25:56 -0600 Subject: [PATCH 08/10] add back cfg --- Dockerfile | 2 +- main/src/main.rs | 3 +++ rust-toolchain.toml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c6c02e4..6b56c79 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ARG BUILD_PLATFORM=linux/amd64 -ARG RUST_VERSION=1.83 +ARG RUST_VERSION=1.81 FROM --platform=${BUILD_PLATFORM} rust:${RUST_VERSION} AS builder RUN rustup target add x86_64-unknown-linux-gnu diff --git a/main/src/main.rs b/main/src/main.rs index d4c0c52..b8bf51e 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -1,6 +1,9 @@ // Copyright 2023-2024, Offchain Labs, Inc. // For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md +// Enable unstable test feature for benchmarks when nightly is available +#![cfg_attr(feature = "nightly", feature(test))] + use alloy_primitives::TxHash; use clap::{ArgGroup, Args, CommandFactory, Parser, Subcommand}; use constants::DEFAULT_ENDPOINT; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 0193dee..1de01fa 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.83.0" +channel = "1.81.0" From 1c0d27f03e73bc4cd215a5b7f222b289839e9bb4 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 12 Dec 2024 15:37:50 -0600 Subject: [PATCH 09/10] revert version --- Dockerfile | 2 +- rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6b56c79..d48e53b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ARG BUILD_PLATFORM=linux/amd64 -ARG RUST_VERSION=1.81 +ARG RUST_VERSION=1.80 FROM --platform=${BUILD_PLATFORM} rust:${RUST_VERSION} AS builder RUN rustup target add x86_64-unknown-linux-gnu diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1de01fa..4d2dee8 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.81.0" +channel = "1.80.0" From f7bccad9525e7230b7c1dad48128f9f025c45ba0 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 12 Dec 2024 15:41:47 -0600 Subject: [PATCH 10/10] tool --- rust-toolchain.toml | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 4d2dee8..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "1.80.0"