Skip to content

Commit

Permalink
build: add --reproducible flag, using docker
Browse files Browse the repository at this point in the history
  • Loading branch information
nick1udwig committed Sep 30, 2024
1 parent 3c76d57 commit 792345e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ async fn fetch_dependencies(
default_world,
vec![], // TODO: what about deps-of-deps?
vec![],
false,
force,
verbose,
true,
Expand Down Expand Up @@ -1026,6 +1027,7 @@ async fn fetch_dependencies(
default_world,
local_dep_deps,
vec![],
false,
force,
verbose,
false,
Expand Down Expand Up @@ -1408,6 +1410,7 @@ pub async fn execute(
default_world: Option<&str>,
local_dependencies: Vec<PathBuf>,
add_paths_to_api: Vec<PathBuf>,
reproducible: bool,
force: bool,
verbose: bool,
ignore_deps: bool, // for internal use; may cause problems when adding recursive deps
Expand All @@ -1427,6 +1430,25 @@ pub async fn execute(
if !force && is_up_to_date(&build_with_features_path, features, package_dir)? {
return Ok(());
}

if reproducible {
let version = env!("CARGO_PKG_VERSION");
let source = package_dir.canonicalize().unwrap();
let source = source.to_str().unwrap();
run_command(
Command::new("docker")
.args(&[
"run",
"--rm",
"--mount",
&format!("type=bind,source={source},target=/input"),
&format!("nick1udwig/buildpackage:{version}"),
]),
true,
)?;
return Ok(());
}

fs::create_dir_all(package_dir.join("target"))?;
fs::write(&build_with_features_path, features)?;

Expand Down
2 changes: 2 additions & 0 deletions src/build_start_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub async fn execute(
default_world: Option<&str>,
local_dependencies: Vec<PathBuf>,
add_paths_to_api: Vec<PathBuf>,
reproducible: bool,
force: bool,
verbose: bool,
) -> Result<()> {
Expand All @@ -32,6 +33,7 @@ pub async fn execute(
default_world,
local_dependencies,
add_paths_to_api,
reproducible,
force,
verbose,
false,
Expand Down
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ async fn execute(
.unwrap_or_default()
.map(|s| PathBuf::from(s))
.collect();
let reproducible = matches.get_one::<bool>("REPRODUCIBLE").unwrap();
let force = matches.get_one::<bool>("FORCE").unwrap();
let verbose = matches.get_one::<bool>("VERBOSE").unwrap();

Expand All @@ -225,6 +226,7 @@ async fn execute(
default_world.map(|w| w.as_str()),
local_dependencies,
add_paths_to_api,
*reproducible,
*force,
*verbose,
false,
Expand Down Expand Up @@ -258,6 +260,7 @@ async fn execute(
.unwrap_or_default()
.map(|s| PathBuf::from(s))
.collect();
let reproducible = matches.get_one::<bool>("REPRODUCIBLE").unwrap();
let force = matches.get_one::<bool>("FORCE").unwrap();
let verbose = matches.get_one::<bool>("VERBOSE").unwrap();

Expand All @@ -272,6 +275,7 @@ async fn execute(
default_world.map(|w| w.as_str()),
local_dependencies,
add_paths_to_api,
*reproducible,
*force,
*verbose,
)
Expand Down Expand Up @@ -690,6 +694,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result<Command> {
.long("add-to-api")
.help("Path to file to add to api.zip (can specify multiple times)")
)
.arg(Arg::new("REPRODUCIBLE")
.action(ArgAction::SetTrue)
.short('r')
.long("reproducible")
.help("Make a reproducible build using Docker")
.required(false)
)
.arg(Arg::new("FORCE")
.action(ArgAction::SetTrue)
.short('f')
Expand Down Expand Up @@ -772,6 +783,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result<Command> {
.help("Pass these comma-delimited feature flags to Rust cargo builds")
.required(false)
)
.arg(Arg::new("REPRODUCIBLE")
.action(ArgAction::SetTrue)
.short('r')
.long("reproducible")
.help("Make a reproducible build using Docker")
.required(false)
)
.arg(Arg::new("FORCE")
.action(ArgAction::SetTrue)
.short('f')
Expand Down
2 changes: 1 addition & 1 deletion src/publish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn make_local_file_link_path(path: &Path, text: &str) -> Result<String> {
}

pub fn make_remote_link(url: &str, text: &str) -> String {
format!("\x1B]8;;{}\x1B\\{}\x1B]8;;\x1B\\", url, text,)
format!("\x1B]8;;{}\x1B\\{}\x1B]8;;\x1B\\", url, text)
}

fn is_valid_kimap_package_name(s: &str) -> bool {
Expand Down
3 changes: 3 additions & 0 deletions src/run_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async fn build_packages(
false,
false,
false,
false,
)
.await?;
start_package::execute(&path, &url).await?;
Expand All @@ -390,6 +391,7 @@ async fn build_packages(
false,
false,
false,
false,
)
.await?;
}
Expand All @@ -408,6 +410,7 @@ async fn build_packages(
false,
false,
false,
false,
)
.await?;
}
Expand Down
20 changes: 20 additions & 0 deletions src/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use fs_err as fs;
use tracing::{info, instrument, warn};

use crate::build::run_command;
use crate::publish::make_remote_link;

const FETCH_NVM_VERSION: &str = "v0.39.7";
const REQUIRED_NODE_MAJOR: u32 = 20;
Expand All @@ -31,6 +32,7 @@ pub enum Dependency {
RustWasm32Wasi,
RustNightlyWasm32Wasi,
WasmTools,
Docker,
}

impl std::fmt::Display for Dependency {
Expand All @@ -46,6 +48,7 @@ impl std::fmt::Display for Dependency {
Dependency::RustWasm32Wasi => write!(f, "rust wasm32-wasip1 target"),
Dependency::RustNightlyWasm32Wasi => write!(f, "rust nightly wasm32-wasip1 target"),
Dependency::WasmTools => write!(f, "wasm-tools"),
Dependency::Docker => write!(f, "docker"),
}
}
}
Expand Down Expand Up @@ -430,6 +433,21 @@ pub fn check_rust_deps() -> Result<Vec<Dependency>> {
Ok(missing_deps)
}

// Check for Foundry deps, returning a Vec of not found: can be automatically fetched?
#[instrument(level = "trace", skip_all)]
pub fn check_docker_deps() -> Result<Vec<Dependency>> {
let mut missing_deps = Vec::new();
if !is_command_installed("docker")? {
missing_deps.push(Dependency::Docker);
// TODO: automated get docker
return Err(eyre!(
"docker not found: please {} and try again",
make_remote_link("https://docs.docker.com/engine/install", "install Docker"),
));
}
Ok(missing_deps)
}

#[instrument(level = "trace", skip_all)]
pub fn get_deps(deps: Vec<Dependency>, verbose: bool) -> Result<()> {
if deps.is_empty() {
Expand Down Expand Up @@ -474,6 +492,7 @@ pub fn get_deps(deps: Vec<Dependency>, verbose: bool) -> Result<()> {
}
Dependency::WasmTools => call_cargo("install wasm-tools", verbose)?,
Dependency::Forge | Dependency::Anvil => install_foundry()?,
Dependency::Docker => {}
}
}
}
Expand All @@ -489,6 +508,7 @@ pub fn execute(verbose: bool) -> Result<()> {
check_py_deps()?;
let mut missing_deps = check_js_deps()?;
missing_deps.append(&mut check_rust_deps()?);
missing_deps.append(&mut check_docker_deps()?);
get_deps(missing_deps, verbose)?;

info!("Done setting up.");
Expand Down

0 comments on commit 792345e

Please sign in to comment.