diff --git a/Dockerfile b/Dockerfile index 7143a4e..d48e53b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ ARG BUILD_PLATFORM=linux/amd64 ARG RUST_VERSION=1.80 -ARG CARGO_STYLUS_VERSION=0.5.6 - 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 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/main/src/check.rs b/main/src/check.rs index 9cbb534..b621cba 100644 --- a/main/src/check.rs +++ b/main/src/check.rs @@ -120,7 +120,8 @@ impl CheckConfig { let toolchain_file_path = PathBuf::from(".").as_path().join(TOOLCHAIN_FILE_NAME); let toolchain_channel = extract_toolchain_channel(&toolchain_file_path)?; let rust_stable = !toolchain_channel.contains("nightly"); - let cfg = BuildConfig::new(rust_stable); + let mut cfg = BuildConfig::new(rust_stable); + 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)?; diff --git a/main/src/main.rs b/main/src/main.rs index acb510f..b8bf51e 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -126,6 +126,9 @@ struct CommonConfig { #[arg(long)] /// Optional max fee per gas in gwei units. max_fee_per_gas_gwei: Option, + /// Specifies the features to use when building the Stylus binary. + #[arg(long)] + features: Option, } #[derive(Subcommand, Clone, Debug)] @@ -258,6 +261,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 +690,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.features)?; let library_extension = if macos { ".dylib" } else { ".so" }; let shared_library = find_shared_library(&args.trace.project, library_extension)?; @@ -704,12 +713,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") diff --git a/main/src/project.rs b/main/src/project.rs index 95f34c8..8b4ef5e 100644 --- a/main/src/project.rs +++ b/main/src/project.rs @@ -38,6 +38,7 @@ pub enum OptLevel { pub struct BuildConfig { pub opt_level: OptLevel, pub stable: bool, + pub features: Option, } impl BuildConfig { @@ -74,6 +75,10 @@ pub fn build_dylib(cfg: BuildConfig) -> Result { cmd.arg("--lib"); cmd.arg("--locked"); + if let Some(features) = cfg.features { + cmd.arg(format!("--features={}", features.clone())); + } + if !cfg.stable { cmd.arg("-Z"); cmd.arg("build-std=std,panic_abort"); diff --git a/main/src/verify.rs b/main/src/verify.rs index c8087f2..82165ae 100644 --- a/main/src/verify.rs +++ b/main/src/verify.rs @@ -64,6 +64,7 @@ pub async fn verify(cfg: VerifyConfig) -> eyre::Result<()> { let build_cfg = project::BuildConfig { opt_level: project::OptLevel::default(), stable: rust_stable, + features: cfg.common_cfg.features.clone(), }; let wasm_file: PathBuf = project::build_dylib(build_cfg.clone()) .map_err(|e| eyre!("could not build project to WASM: {e}"))?;