Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Default to release for wasm on debug builds
  • Loading branch information
athei committed Jan 30, 2022
commit 68bb5765b03a7715e4dbc2052969456666974d75
4 changes: 3 additions & 1 deletion utils/wasm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ const SKIP_BUILD_ENV: &str = "SKIP_WASM_BUILD";
/// Environment variable to force a certain build type when building the wasm binary.
/// Expects "debug", "release" or "production" as value.
///
/// By default the WASM binary uses the same build type as the main cargo build.
/// When unset the WASM binary uses the same build type as the main cargo build with
/// the exception of a debug build: In this case the wasm build defaults to `release` in
/// order to avoid a slowdown when not explicitly requested.
const WASM_BUILD_TYPE_ENV: &str = "WASM_BUILD_TYPE";

/// Environment variable to extend the `RUSTFLAGS` variable given to the wasm build.
Expand Down
35 changes: 22 additions & 13 deletions utils/wasm-builder/src/wasm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,14 @@ impl Profile {
///
/// Can be overriden by setting [`crate::WASM_BUILD_TYPE_ENV`].
fn detect(wasm_project: &Path) -> Profile {
let name = if let Ok(name) = env::var(crate::WASM_BUILD_TYPE_ENV) {
name
let (name, overriden) = if let Ok(name) = env::var(crate::WASM_BUILD_TYPE_ENV) {
(name, true)
} else {
// First go backwards to the beginning of the target directory.
// Then go forwards to find the "wbuild" directory.
// We need to go backwards first because when starting from the root there
// might be a chance that someone has a "wbuild" directory somewhere in the path.
wasm_project
let name = wasm_project
.components()
.rev()
.take_while(|c| c.as_os_str() != "target")
Expand All @@ -466,18 +466,27 @@ impl Profile {
.as_os_str()
.to_str()
.unwrap()
.to_string()
.to_string();
(name, false)
};
if let Some(profile) = Profile::iter().find(|p| p.directory() == name) {
return profile
match (Profile::iter().find(|p| p.directory() == name), overriden) {
// When not overriden by a env variable we default to using the `Release` profile
// for the wasm build even when the main build uses the debug build. This
// is because the `Debug` profile is too slow for normal development activities.
(Some(Profile::Debug), false) => Profile::Release,
// For any other profile or when overriden we take it at face value.
(Some(profile), _) => profile,
// Invalid profile specified.
(None, _) => {
// We use println! + exit instead of a panic in order to have a cleaner output.
println!(
"Unexpected profile name: `{}`. One of the following is expected: {:?}",
name,
Profile::iter().map(|p| p.directory()).collect::<Vec<_>>(),
);
process::exit(1);
},
}
// We use println! + exit instead of a panic in order to have a cleaner output.
println!(
"Unexpected profile name: `{}`. One of the following is expected: {:?}",
name,
Profile::iter().map(|p| p.directory()).collect::<Vec<_>>(),
);
process::exit(1);
}

/// The name of the profile as supplied to the cargo `--profile` cli option.
Expand Down