diff --git a/Cargo.lock b/Cargo.lock index 586ca61..8cce4a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1011,7 +1011,7 @@ dependencies = [ [[package]] name = "cargo-stylus" -version = "0.5.1" +version = "0.5.2" dependencies = [ "alloy-contract", "alloy-ethers-typecast", @@ -1053,7 +1053,7 @@ dependencies = [ [[package]] name = "cargo-stylus-example" -version = "0.5.1" +version = "0.5.2" dependencies = [ "clap", ] diff --git a/Cargo.toml b/Cargo.toml index 6a3355a..c12318e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "2" [workspace.package] authors = ["Offchain Labs"] -version = "0.5.1" +version = "0.5.2" edition = "2021" homepage = "https://arbitrum.io" license = "MIT OR Apache-2.0" diff --git a/Dockerfile b/Dockerfile index 9177d7f..48fe819 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ RUN apt-get update && apt-get install -y git RUN rustup target add x86_64-unknown-linux-gnu RUN git clone https://github.com/offchainlabs/cargo-stylus.git WORKDIR /cargo-stylus -RUN git checkout v0.5.1 +RUN git checkout v0.5.2 RUN cargo build --release --manifest-path main/Cargo.toml FROM --platform=linux/amd64 rust:1.80 COPY --from=builder /cargo-stylus/target/release/cargo-stylus /usr/local/bin/cargo-stylus \ No newline at end of file diff --git a/main/src/docker.rs b/main/src/docker.rs index 0b892f6..62ad2c1 100644 --- a/main/src/docker.rs +++ b/main/src/docker.rs @@ -12,8 +12,8 @@ use crate::constants::TOOLCHAIN_FILE_NAME; use crate::macros::greyln; use crate::project::extract_toolchain_channel; -fn image_exists() -> Result { - let image_name = format!("cargo-stylus-base:{}", env!("CARGO_PKG_VERSION")); +fn image_exists(cargo_stylus_version: &str) -> Result { + let image_name = format!("cargo-stylus-base:{}", cargo_stylus_version); let output = Command::new("docker") .arg("images") .arg(image_name) @@ -37,12 +37,16 @@ a reproducible deployment, or opt out by using the --no-verify flag for local bu Ok(output.stdout.iter().filter(|c| **c == b'\n').count() > 1) } -fn create_image(version: &str) -> Result<()> { - if image_exists()? { +fn create_image(cargo_stylus_version: Option, version: &str) -> Result<()> { + let cargo_stylus_version = + cargo_stylus_version.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()); + if image_exists(&cargo_stylus_version)? { return Ok(()); } - let pkg_version = env!("CARGO_PKG_VERSION"); - let name = format!("cargo-stylus-base-{}-toolchain-{}", pkg_version, version); + let name = format!( + "cargo-stylus-base-{}-toolchain-{}", + cargo_stylus_version, version + ); println!("Building Docker image for Rust toolchain {}", version,); let mut child = Command::new("docker") .arg("build") @@ -62,7 +66,7 @@ fn create_image(version: &str) -> Result<()> { RUN rustup target add wasm32-unknown-unknown RUN rustup component add rust-src --toolchain {}-x86_64-unknown-linux-gnu ", - pkg_version, + cargo_stylus_version, version, version, version, @@ -71,9 +75,17 @@ fn create_image(version: &str) -> Result<()> { Ok(()) } -fn run_in_docker_container(version: &str, command_line: &[&str]) -> Result<()> { - let pkg_version = env!("CARGO_PKG_VERSION"); - let name = format!("cargo-stylus-base-{}-toolchain-{}", pkg_version, version); +fn run_in_docker_container( + cargo_stylus_version: Option, + toolchain_version: &str, + command_line: &[&str], +) -> Result<()> { + let cargo_stylus_version = + cargo_stylus_version.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()); + let name = format!( + "cargo-stylus-base-{}-toolchain-{}", + cargo_stylus_version, toolchain_version + ); let dir = std::env::current_dir().map_err(|e| eyre!("failed to find current directory: {e}"))?; Command::new("docker") @@ -93,7 +105,10 @@ fn run_in_docker_container(version: &str, command_line: &[&str]) -> Result<()> { Ok(()) } -pub fn run_reproducible(command_line: &[String]) -> Result<()> { +pub fn run_reproducible( + cargo_stylus_version: Option, + command_line: &[String], +) -> Result<()> { verify_valid_host()?; let toolchain_file_path = PathBuf::from(".").as_path().join(TOOLCHAIN_FILE_NAME); let toolchain_channel = extract_toolchain_channel(&toolchain_file_path)?; @@ -105,8 +120,8 @@ pub fn run_reproducible(command_line: &[String]) -> Result<()> { for s in command_line.iter() { command.push(s); } - create_image(&toolchain_channel)?; - run_in_docker_container(&toolchain_channel, &command) + create_image(cargo_stylus_version.clone(), &toolchain_channel)?; + run_in_docker_container(cargo_stylus_version, &toolchain_channel, &command) } fn verify_valid_host() -> Result<()> { diff --git a/main/src/main.rs b/main/src/main.rs index ea2bd59..3b2d63f 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -215,6 +215,10 @@ struct DeployConfig { /// builds, but at the risk of not having a reproducible contract for verification purposes. #[arg(long)] no_verify: bool, + /// Cargo stylus version when deploying reproducibly to downloads the corresponding cargo-stylus-base Docker image. + /// If not set, uses the default version of the local cargo stylus binary. + #[arg(long)] + cargo_stylus_version: Option, } #[derive(Args, Clone, Debug)] @@ -228,6 +232,10 @@ pub struct VerifyConfig { /// If specified, will not run the command in a reproducible docker container. Useful for local /// builds, but at the risk of not having a reproducible contract for verification purposes. no_verify: bool, + /// Cargo stylus version when deploying reproducibly to downloads the corresponding cargo-stylus-base Docker image. + /// If not set, uses the default version of the local cargo stylus binary. + #[arg(long)] + cargo_stylus_version: Option, } #[derive(Args, Clone, Debug)] @@ -324,7 +332,7 @@ impl fmt::Display for DeployConfig { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "{} {} {} {}", + "{} {} {} {} {}", self.check_config, self.auth, match self.estimate_gas { @@ -335,6 +343,10 @@ impl fmt::Display for DeployConfig { true => "--no-verify".to_string(), false => "".to_string(), }, + match self.cargo_stylus_version.as_ref() { + Some(version) => format!("--cargo-stylus-version={}", version), + None => "".to_string(), + }, ) } } @@ -368,13 +380,17 @@ impl fmt::Display for VerifyConfig { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "{} --deployment-tx={} {}", + "{} --deployment-tx={} {} {}", self.common_cfg, self.deployment_tx, match self.no_verify { true => "--no-verify".to_string(), false => "".to_string(), - } + }, + match self.cargo_stylus_version.as_ref() { + Some(version) => format!("--cargo-stylus-version={}", version), + None => "".to_string(), + }, ) } } @@ -501,7 +517,7 @@ async fn main_impl(args: Opts) -> Result<()> { .collect::>(); commands.extend(config_args); run!( - docker::run_reproducible(&commands), + docker::run_reproducible(config.cargo_stylus_version, &commands), "failed reproducible run" ); } @@ -523,7 +539,7 @@ async fn main_impl(args: Opts) -> Result<()> { .collect::>(); commands.extend(config_args); run!( - docker::run_reproducible(&commands), + docker::run_reproducible(config.cargo_stylus_version, &commands), "failed reproducible run" ); }