From 42acb72c54e84149e4102cd22bca107f3e5a9e19 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 10 Aug 2021 11:08:30 -0700 Subject: [PATCH] fuzz: retrieve the WebAssembly spec repository in `build.rs` To avoid the large download size of the spec repository mentioned [here](https://github.com/bytecodealliance/wasmtime/pull/3124#discussion_r684605984), this change removes it as a submodule and instead clones it shallowly when the directory is empty (or not present) when `build.rs` is run. --- .gitmodules | 4 --- crates/fuzzing/wasm-spec-interpreter/build.rs | 33 ++++++++++++++++++- .../wasm-spec-interpreter/ocaml/.gitignore | 1 + .../fuzzing/wasm-spec-interpreter/ocaml/spec | 1 - 4 files changed, 33 insertions(+), 6 deletions(-) delete mode 160000 crates/fuzzing/wasm-spec-interpreter/ocaml/spec diff --git a/.gitmodules b/.gitmodules index 725b4b4dc28c..ee264b99c477 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,7 +13,3 @@ [submodule "crates/wasi-crypto/spec"] path = crates/wasi-crypto/spec url = https://github.com/WebAssembly/wasi-crypto.git -[submodule "crates/fuzzing/wasm-spec-interpreter/ocaml/spec"] - path = crates/fuzzing/wasm-spec-interpreter/ocaml/spec - url = https://github.com/WebAssembly/spec - shallow = true diff --git a/crates/fuzzing/wasm-spec-interpreter/build.rs b/crates/fuzzing/wasm-spec-interpreter/build.rs index 61e8c316eb31..4d074febbc13 100644 --- a/crates/fuzzing/wasm-spec-interpreter/build.rs +++ b/crates/fuzzing/wasm-spec-interpreter/build.rs @@ -5,10 +5,12 @@ /// approach to avoid missing symbols was to imitate `dune`: I observed `rm -rf /// _build && dune build ./ocaml/interpret.exe.o --display=verbose` and used /// that as a pattern, now encoded in `ocaml/Makefile` for easier debugging. -use std::{env, process::Command}; +use std::{env, path::PathBuf, process::Command}; const LIB_NAME: &'static str = "interpret"; const OCAML_DIR: &'static str = "ocaml"; +const SPEC_DIR: &'static str = "ocaml/spec"; +const SPEC_REPOSITORY: &'static str = "https://github.com/bytecodealliance/wasm-spec-mirror"; fn main() { if cfg!(feature = "build-libinterpret") { @@ -28,6 +30,11 @@ fn build() { println!("cargo:rustc-link-search={}", other_dir.to_str().unwrap()); println!("cargo:rustc-link-lib=static={}", LIB_NAME); } else { + // Ensure the spec repository is present. + if is_spec_repository_empty(SPEC_DIR) { + retrieve_spec_repository(SPEC_REPOSITORY, SPEC_DIR) + } + // Build the library to link to. build_lib(out_dir, OCAML_DIR); println!("cargo:rustc-link-search={}", out_dir); @@ -52,3 +59,27 @@ fn build_lib(out_dir: &str, ocaml_dir: &str) { "Failed to build the OCaml library using 'make'." ) } + +// Check if the spec repository directory contains any files. +fn is_spec_repository_empty(destination: &str) -> bool { + PathBuf::from(destination) + .read_dir() + .map(|mut i| i.next().is_none()) + .unwrap_or(true) +} + +// Clone the spec repository into `destination`. This exists due to the large +// size of the dependencies (e.g. KaTeX) that are pulled if this were cloned +// recursively as a submodule. +fn retrieve_spec_repository(repository: &str, destination: &str) { + let status = Command::new("git") + .arg("clone") + .arg("--depth") + .arg("1") + .arg(repository) + .arg(destination) + .status() + .expect("Failed to execute 'git' command to clone spec repository."); + + assert!(status.success(), "Failed to retrieve the spec repository.") +} diff --git a/crates/fuzzing/wasm-spec-interpreter/ocaml/.gitignore b/crates/fuzzing/wasm-spec-interpreter/ocaml/.gitignore index e35d8850c968..1e82b679cf42 100644 --- a/crates/fuzzing/wasm-spec-interpreter/ocaml/.gitignore +++ b/crates/fuzzing/wasm-spec-interpreter/ocaml/.gitignore @@ -1 +1,2 @@ _build +spec diff --git a/crates/fuzzing/wasm-spec-interpreter/ocaml/spec b/crates/fuzzing/wasm-spec-interpreter/ocaml/spec deleted file mode 160000 index 46cf27ce076e..000000000000 --- a/crates/fuzzing/wasm-spec-interpreter/ocaml/spec +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 46cf27ce076e1213e45b89ffdc99df4499b3cb33