Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nightly rust feature #854

Open
F8RZD opened this issue Aug 20, 2024 · 3 comments
Open

nightly rust feature #854

F8RZD opened this issue Aug 20, 2024 · 3 comments

Comments

@F8RZD
Copy link
Contributor

F8RZD commented Aug 20, 2024

does trunk support adding nightly flags to rustc and cargo ?

I'm specifically interested in build_std and panic_immediate_abort.
combination of these two practically removes all panic related boiler plate and strings reducing the binary size drastically which is an essential need in wasm.

does trunk support passing those arguments?

@ctron
Copy link
Collaborator

ctron commented Sep 6, 2024

Sorry for the late response. I seem to have overlooked this one.

Right now, as far as I remember, you can't add flags like this.

However, you can add a rust-toolchain.toml, to choose the nightly (or other) toolchain explicitly. And you should be able to use .cargo/config (rustflags) to specify additional arguments.

So it should all be provided by standard Rust tooling.

@BGR360
Copy link
Contributor

BGR360 commented Sep 6, 2024

I could really use an option in Trunk to pass arbitrary flags to cargo.

My use case is the same as @F8RZD, except I need to not supply those flags when building my project for non-web platforms.

The only way I've been able to find to do this is by having a separate Cargo config file .config/web.toml and to pass --config .config/web.toml to every Cargo command. Cargo does not provide any way to statically configure whether the build-std feature should be used depending on the target.

I would be happy with any of the following implementations in Trunk:

  • CLI flag:
    trunk serve --cargo-flags "--config .config/web.toml"
  • Environment variable:
    TRUNK_CARGO_FLAGS="--config .config/web.toml" trunk serve
  • Trunk.toml file:
    [build]
    cargo_flags = ["--config .config/web.toml"]
  • <link rel="rust"> attribute:
    <link data-trunk rel="rust" data-cargo-flags="--config .config/web.toml"

@F8RZD
Copy link
Contributor Author

F8RZD commented Nov 17, 2024

So...

I never really tried this one since I created the issue
I'm gonna rephrase it a little cause tonight I was unable to make it work (again).

this is my build script:

#!/bin/python


import subprocess
import os

TRUNK = False

target = "wasm32-unknown-unknown"
os.environ['RUSTFLAGS'] = '-Cpanic=abort -Copt-level=z -Clto=fat -Ccodegen-units=1 -Cstrip=symbols'
os.environ['CARGO_BUILD_TARGET'] = target


if not TRUNK:
    subprocess.run(
        [
            'cargo', '+nightly', 'build', '--release',
            '-Z', 'build-std=std,panic_abort',
            '-Z', 'build-std-features=panic_immediate_abort',
            '--target',  target
        ]
    )

if TRUNK:
    subprocess.run(
        [
            'trunk', 'build', '--release'
        ]
    )

there is one TRUNK variable which controls what commands get ran.

when I run with TRUNK=True I get a 1.8MB .wasm file (pre optimizations of wasm-bindgen and wasm-opt)
then I strings frontend.wasm | grep panic and get:

unit valueOption valuenewtype structsequencemapenumunit variantnewtype varianttuple variantstruct variantexplicit panic/home/f8rzd/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.215/src/de/mod.rs
panicked at :
cannot modify the panic hook from a panicking thread
std/src/panicking.rs
)console_error_panic_hook-f178a9a18eb274f1

what I get when I do all the steps with TRUNK=False:
1.7MB .wasm file and

)console_error_panic_hook-f178a9a18eb274f1

-Z flags cannot be passed through RUSTFLAGS environment variable ( as far as I tested ) and they should be passed as arguments to cargo

how can I get trunk to do panic_immediate_abort with my current configuration?

any help or direction is greatly appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants