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

Consider removing useless -sign-ext flag in substrate-wasm-builder #5777

Closed
2 tasks done
StackOverflowExcept1on opened this issue Sep 19, 2024 · 9 comments · Fixed by #7008
Closed
2 tasks done

Consider removing useless -sign-ext flag in substrate-wasm-builder #5777

StackOverflowExcept1on opened this issue Sep 19, 2024 · 9 comments · Fixed by #7008
Labels
I5-enhancement An additional feature request. I10-unconfirmed Issue might be valid, but it's not yet known.

Comments

@StackOverflowExcept1on
Copy link
Contributor

StackOverflowExcept1on commented Sep 19, 2024

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Motivation

https://github.com/rust-lang/blog.rust-lang.org/blob/4a72d620768932213baf39b03c6f1e61c00cd038/posts/2024-08-26-webassembly-targets-change-in-default-target-features.md

Request

Should be removed here

let mut rustflags = String::new();
match target {
RuntimeTarget::Wasm => {
rustflags.push_str(
"-C target-cpu=mvp -C target-feature=-sign-ext -C link-arg=--export-table ",
);
},

Solution

No response

Are you willing to help with this request?

Maybe (please elaborate above)

@StackOverflowExcept1on StackOverflowExcept1on added the I5-enhancement An additional feature request. label Sep 19, 2024
@github-actions github-actions bot added the I10-unconfirmed Issue might be valid, but it's not yet known. label Sep 19, 2024
@StackOverflowExcept1on StackOverflowExcept1on changed the title Consider to disable multi-value and reference-types features Consider disabling multi-value and reference-types features Sep 19, 2024
@bkchr
Copy link
Member

bkchr commented Sep 19, 2024

Do you have a little bit more context?

@StackOverflowExcept1on
Copy link
Contributor Author

@bkchr Rust 1.82 (stable Oct 17) enables multi-value and reference-types by default. I think it makes sense to additionally disable these features.

@nazar-pc
Copy link
Contributor

According to link you have provided -C target-cpu=mvp is already sufficient to disable all of these features, not sure why Substrate also has -C target-feature=-sign-ext given that same document explicitly mentions that it'll be disabled for mvp CPU.

@StackOverflowExcept1on
Copy link
Contributor Author

StackOverflowExcept1on commented Sep 20, 2024

Yep, maybe it make sense just leave -C target-cpu=mvp since Rust added more documentation about this stuff

@StackOverflowExcept1on StackOverflowExcept1on changed the title Consider disabling multi-value and reference-types features Consider removing useless -sign-ext flag in substrate-wasm-builder Sep 20, 2024
@bkchr
Copy link
Member

bkchr commented Sep 22, 2024

not sure why Substrate also has -C target-feature=-sign-ext given that same document explicitly mentions that it'll be disabled for mvp CPU.

Apparently it did not worked before: paritytech/substrate#13804 (comment)

AFAIR we also just disabled this feature because there were issues with our wasm parser and not because we didn't wanted this feature.

CC @koute

@StackOverflowExcept1on
Copy link
Contributor Author

StackOverflowExcept1on commented Dec 14, 2024

@bkchr @koute We could switch to the new target wasm32v1-none (it will be stabilized starting with Rust 1.84 and no more hacks with RUSTC_BOOTSTRAP=1) instead of wasm32-unknown-unknown.

@bkchr
Copy link
Member

bkchr commented Dec 14, 2024

Sounds reasonable

@StackOverflowExcept1on
Copy link
Contributor Author

@bkchr @koute I could do PR that would change the target to wasm32v1-none, but it doesn't have std as wasm32-unknown-unknown. Also, I don't fully understand why every runtime has this line:

#![cfg_attr(not(feature = "std"), no_std)]

I.e. does this mean that the runtime requires std? In which cases does it use std and in which cases does it not?

@bkchr
Copy link
Member

bkchr commented Dec 16, 2024

I.e. does this mean that the runtime requires std? In which cases does it use std and in which cases does it not?

No, the piece of code you have linked means that if std feature is not set, no_std is set to announce to rustc that std is not required.

I could do PR that would change the target to wasm32v1-none, but it doesn't have std as wasm32-unknown-unknown.

This would need to be done in a backwards compatible way, aka only do so if the new target exists.

github-merge-queue bot pushed a commit that referenced this issue Feb 9, 2025
# Description

Resolves #5777

Previously `wasm-builder` used hacks such as `-Zbuild-std` (required
`rust-src` component) and `RUSTC_BOOTSTRAP=1` to build WASM runtime
without WASM features: `sign-ext`, `multivalue` and `reference-types`,
but since Rust 1.84 (will be stable on 9 January, 2025) the situation
has improved as there is new
[`wasm32v1-none`](https://doc.rust-lang.org/beta/rustc/platform-support/wasm32v1-none.html)
target that disables all "post-MVP" WASM features except
`mutable-globals`.

Previously, your `rust-toolchain.toml` looked like this:

```toml
[toolchain]
channel = "stable"
components = ["rust-src"]
targets = ["wasm32-unknown-unknown"]
profile = "default"
```

It should now be updated to something like this:

```toml
[toolchain]
channel = "stable"
targets = ["wasm32v1-none"]
profile = "default"
```

To build the runtime:

```bash
cargo build --package minimal-template-runtime --release
```

## Integration

If you are using Rust 1.84 and above, then install the `wasm32v1-none`
target instead of `wasm32-unknown-unknown` as shown above. You can also
remove the unnecessary `rust-src` component.

Also note the slight differences in conditional compilation:
- `wasm32-unknown-unknown`: `#[cfg(all(target_family = "wasm", target_os
= "unknown"))]`
- `wasm32v1-none`: `#[cfg(all(target_family = "wasm", target_os =
"none"))]`

Avoid using `target_os = "unknown"` in `#[cfg(...)]` or
`#[cfg_attr(...)]` and instead use `target_family = "wasm"` or
`target_arch = "wasm32"` in the runtime code.

## Review Notes

Wasm builder requires the following prerequisites for building the WASM
binary:
- Rust >= 1.68 and Rust < 1.84:
  - `wasm32-unknown-unknown` target
  - `rust-src` component
- Rust >= 1.84:
  - `wasm32v1-none` target
- no more `-Zbuild-std` and `RUSTC_BOOTSTRAP=1` hacks and `rust-src`
component requirements!

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <info@kchr.de>
clangenb pushed a commit to clangenb/polkadot-sdk that referenced this issue Feb 19, 2025
…ytech#7008)

# Description

Resolves paritytech#5777

Previously `wasm-builder` used hacks such as `-Zbuild-std` (required
`rust-src` component) and `RUSTC_BOOTSTRAP=1` to build WASM runtime
without WASM features: `sign-ext`, `multivalue` and `reference-types`,
but since Rust 1.84 (will be stable on 9 January, 2025) the situation
has improved as there is new
[`wasm32v1-none`](https://doc.rust-lang.org/beta/rustc/platform-support/wasm32v1-none.html)
target that disables all "post-MVP" WASM features except
`mutable-globals`.

Previously, your `rust-toolchain.toml` looked like this:

```toml
[toolchain]
channel = "stable"
components = ["rust-src"]
targets = ["wasm32-unknown-unknown"]
profile = "default"
```

It should now be updated to something like this:

```toml
[toolchain]
channel = "stable"
targets = ["wasm32v1-none"]
profile = "default"
```

To build the runtime:

```bash
cargo build --package minimal-template-runtime --release
```

## Integration

If you are using Rust 1.84 and above, then install the `wasm32v1-none`
target instead of `wasm32-unknown-unknown` as shown above. You can also
remove the unnecessary `rust-src` component.

Also note the slight differences in conditional compilation:
- `wasm32-unknown-unknown`: `#[cfg(all(target_family = "wasm", target_os
= "unknown"))]`
- `wasm32v1-none`: `#[cfg(all(target_family = "wasm", target_os =
"none"))]`

Avoid using `target_os = "unknown"` in `#[cfg(...)]` or
`#[cfg_attr(...)]` and instead use `target_family = "wasm"` or
`target_arch = "wasm32"` in the runtime code.

## Review Notes

Wasm builder requires the following prerequisites for building the WASM
binary:
- Rust >= 1.68 and Rust < 1.84:
  - `wasm32-unknown-unknown` target
  - `rust-src` component
- Rust >= 1.84:
  - `wasm32v1-none` target
- no more `-Zbuild-std` and `RUSTC_BOOTSTRAP=1` hacks and `rust-src`
component requirements!

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <info@kchr.de>
kayabaNerve pushed a commit to serai-dex/polkadot-sdk that referenced this issue Feb 26, 2025
…ytech#7008)

Resolves paritytech#5777

Previously `wasm-builder` used hacks such as `-Zbuild-std` (required
`rust-src` component) and `RUSTC_BOOTSTRAP=1` to build WASM runtime
without WASM features: `sign-ext`, `multivalue` and `reference-types`,
but since Rust 1.84 (will be stable on 9 January, 2025) the situation
has improved as there is new
[`wasm32v1-none`](https://doc.rust-lang.org/beta/rustc/platform-support/wasm32v1-none.html)
target that disables all "post-MVP" WASM features except
`mutable-globals`.

Previously, your `rust-toolchain.toml` looked like this:

```toml
[toolchain]
channel = "stable"
components = ["rust-src"]
targets = ["wasm32-unknown-unknown"]
profile = "default"
```

It should now be updated to something like this:

```toml
[toolchain]
channel = "stable"
targets = ["wasm32v1-none"]
profile = "default"
```

To build the runtime:

```bash
cargo build --package minimal-template-runtime --release
```

If you are using Rust 1.84 and above, then install the `wasm32v1-none`
target instead of `wasm32-unknown-unknown` as shown above. You can also
remove the unnecessary `rust-src` component.

Also note the slight differences in conditional compilation:
- `wasm32-unknown-unknown`: `#[cfg(all(target_family = "wasm", target_os
= "unknown"))]`
- `wasm32v1-none`: `#[cfg(all(target_family = "wasm", target_os =
"none"))]`

Avoid using `target_os = "unknown"` in `#[cfg(...)]` or
`#[cfg_attr(...)]` and instead use `target_family = "wasm"` or
`target_arch = "wasm32"` in the runtime code.

Wasm builder requires the following prerequisites for building the WASM
binary:
- Rust >= 1.68 and Rust < 1.84:
  - `wasm32-unknown-unknown` target
  - `rust-src` component
- Rust >= 1.84:
  - `wasm32v1-none` target
- no more `-Zbuild-std` and `RUSTC_BOOTSTRAP=1` hacks and `rust-src`
component requirements!

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <info@kchr.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I5-enhancement An additional feature request. I10-unconfirmed Issue might be valid, but it's not yet known.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants