Skip to content

Broken examples when compiling with nightly rust and following size optimizations #2696

Closed
@WorldSEnder

Description

@WorldSEnder

Problem

When following the size recommendations from the Optimization page and compiling the boids and password_size examples in current nightly rust, they fail to produce browser-compatible javascript.

The be more precise the generated js causes an error when loaded by the browser such as

Uncaught TypeError: Error resolving module specifier “env”. Relative module specifiers must start with “./”, “../” or “/”.

The deeper problem is two-fold. First, a compiler bug, rust-lang/rust#96486, results in some symbols in the binary, mainly

undefined symbol: core::intrinsics::const_eval_select

This error is then converted, I assume by wasm-bindgen, to an externally linked method and "mitigated" by generating an import for the (non-existent) env module in the generated javascript wrapper. I think it should rather error out, as it effectively hides a compiler bug, but it is what it be.

Steps To Reproduce

Enable the following options in .cargo/config.toml

[unstable]
build-std = ["std"]

and lto in Cargo.toml

[profile.release]
# optimization for size ( more aggressive )
opt-level = 'z'
# link time optimization using using whole-program analysis
lto = true

Then compile the examples with RUSTUP_TOOLCHAIN="nightly" trunk build --release.

Expected behavior

A clean and working wasm is produced.

Environment:

  • Yew version: master
  • Rust version: rustc 1.62.0-nightly (18f314e70 2022-04-24)
  • Build tool, if relevant: trunk

Questionnaire

  • I would like to fix and I have a solution

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ciArea: The continuous integrationA-examplesArea: The examplesblockedbug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions