Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Remove build.rs
Browse files Browse the repository at this point in the history
While working on tests for `get_deployments()`, I found that any changed to
`src/settings/toml/tests/mod.rs` would cause the whole Wrangler library to be rebuilt, not just the
tests. I found it was because Cargo reran the build.rs on every change to every file, which was far slower than necessary.
I could have changed the build script to output `rerun-if-changed`, but it turns out it wasn't even
necessary in the first place; so this improves the first-time build time as well.

- Use `CARGO_MANIFEST_DIR` instead of the working directory of the build script

  These are always the same. This also allows using the env variable directly instead of removing the quotes after the fact

- Use `--cfg debug_assertions` instead of the `PROFILE` cargo sets for build scripts

  In theory these could be different, but in practice we never build release artifacts with debug
  assertions, so this shouldn't affect the behavior unless someone explicitly builds from source and
  also modifies `Cargo.toml` to enable assertions.
  • Loading branch information
jyn514 committed Aug 16, 2021
1 parent 19cdb32 commit 20a5cd4
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 39 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ description = "Command-line interface for all things Cloudflare Workers"
readme = "README.md"
repository = "https://github.com/cloudflare/wrangler"
categories = ["wasm", "development-tools", "command-line-utilities", "web-programming"]
build = "build.rs"

[dependencies]
anyhow = "1.0"
Expand Down
22 changes: 0 additions & 22 deletions build.rs

This file was deleted.

5 changes: 1 addition & 4 deletions src/install/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ pub const x86_64: bool = cfg!(target_arch = "x86_64");
pub const aarch64: bool = cfg!(target_arch = "aarch64");

// Capture if {Wrangler} is in release or debug mode
pub const DEBUG: bool = cfg!(feature = "debug");

// Capture source location, only in debug mode.
pub const SOURCE_DIR: &str = env!("SOURCE_DIR");
pub const DEBUG: bool = cfg!(debug_assertions);
10 changes: 1 addition & 9 deletions src/wranglerjs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,10 @@ fn env_dep_installed(tool: &str) -> Result<()> {
Ok(())
}

// Use the env-provided source directory and remove the quotes
fn get_source_dir() -> PathBuf {
let mut dir = install::target::SOURCE_DIR.to_string();
dir.remove(0);
dir.remove(dir.len() - 1);
Path::new(&dir).to_path_buf()
}

// Install {wranglerjs} from our GitHub releases
fn install() -> Result<PathBuf> {
let wranglerjs_path = if install::target::DEBUG {
let source_path = get_source_dir();
let source_path = Path::new(env!("CARGO_MANIFEST_DIR"));
let wranglerjs_path = source_path.join("wranglerjs");
log::info!("wranglerjs at: {:?}", wranglerjs_path);
wranglerjs_path
Expand Down
6 changes: 3 additions & 3 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,11 @@ fn build_fails_with(fixture: &Fixture, expected_message: &str) {
build.arg("build");

let output = build.output().expect("failed to execute process");
let stderr = str::from_utf8(&output.stderr).unwrap();
eprintln!("{}", stderr);
assert!(!output.status.success());
assert!(
str::from_utf8(&output.stderr)
.unwrap()
.contains(expected_message),
stderr.contains(expected_message),
"expected {:?} not found, given: {:?}",
expected_message,
str::from_utf8(&output.stderr)
Expand Down

0 comments on commit 20a5cd4

Please sign in to comment.