Skip to content

Without --release, no wasm-opt is performed, despite custom profiles. #933

Open
@simbleau

Description

@simbleau

As discovered in #605,

Using a --cargo-profile which inherits from release does no wasm-optimization.

This is because the release flag has many opinions that shadow a custom profile, primarily around wasm optimization.

Example 1:

        let wasm_opt = attrs
            .get("data-wasm-opt")
            .map(|val| val.parse())
            .transpose()?
            .unwrap_or_else(|| {
                if cfg.release {
                    Default::default()
                } else {
                    WasmOptLevel::Off
                }
            });

Example 2:

    async fn wasm_opt_build(&self, wasm_name: &str) -> Result<()> {
        // If not in release mode, we skip calling wasm-opt.
        if !self.cfg.release {
            return Ok(());
        }

This shouldn't happen if a custom profile is applied, since I specified my own optimization level (i.e. opt-level = 'z') in a custom wasm-release profile. Currently, if I don't add --release, my custom profile's opt-level is skipped.

Thus, I'd propose the following:

  • Add a new --opt-level config, which will accept an opt level. Currently it is an attribute in documents, but doesn't have a CLI flag. Opt level should fall back to a sensible default if --release is used, but do nothing if a cargo profile is used.
  • If --opt-level is absent, and --release is not used, skip wasm-opt.

Hence, using a profiles should behave as such:

trunk build --release
  • Builds the release cargo profile
  • Runs wasm-opt with a default optimization level (current behavior)
trunk build --cargo-profile wasm-release
  • Builds the wasm-release cargo profile
  • Skips wasm-opt
trunk build --cargo-profile wasm-release --opt-level z
  • Builds the wasm-release cargo profile
  • Runs wasm-opt with a aggresize size ('z') optimization level

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions