Skip to content

Add an option to specify CFLAGS for wasm features and make lime1 the default #527

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yamt
Copy link
Contributor

@yamt yamt commented Apr 28, 2025

Add a cmake option WASI_SDK_CPU_CFLAGS to specify CFLAGS to control wasm features to enable/disable.
Make the default -mcpu=lime1.

Comparing to the default "generic" target of the recent llvm, this effectively

  • disables reference-types and bulk-memory (enable their partial counterparts instead)
  • enables extended-const

Note: as of writing this, a few popular runtimes, including wasm3 and wasm-micro-runtime,
don't support extented-const yet.

Note: regardless of this, wasi-libc enables necessary features for certain files. (bulk-memory and exception-handling)

cf. #525

References:
https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md
bytecodealliance/wasm-micro-runtime#4272

@yamt yamt force-pushed the lime1 branch 2 times, most recently from 5e94f81 to c6d8505 Compare April 28, 2025 10:56
@sbc100
Copy link
Member

sbc100 commented Apr 28, 2025

Should we have the wasi target default to lime1 instead?

@yamt
Copy link
Contributor Author

yamt commented May 2, 2025

Should we have the wasi target default to lime1 instead?

it's a valid solution. my feeling is it's app developers' choice which set of features it targets to though.

the intention of this PR is "do not enable extra features we ourselves (eg. libc) doesn't benefit from".

@sbc100
Copy link
Member

sbc100 commented May 2, 2025

Should we have the wasi target default to lime1 instead?

it's a valid solution. my feeling is it's app developers' choice which set of features it targets to though.

Up to a point this is true, but we also what sensible defaults. Developers who want to target specs older than out defaults can/should be asked to rebuild libc themselves, right?

My understanding was the lime1 was specifically designed as a sensible subset of generic that project like wasi-libc could use.

the intention of this PR is "do not enable extra features we ourselves (eg. libc) doesn't benefit from".

extended-const does benefit shared library builds (it allows data segments to express their offset without extra startup code).

@yamt
Copy link
Contributor Author

yamt commented May 6, 2025

Should we have the wasi target default to lime1 instead?

it's a valid solution. my feeling is it's app developers' choice which set of features it targets to though.

Up to a point this is true, but we also what sensible defaults. Developers who want to target specs older than out defaults can/should be asked to rebuild libc themselves, right?

My understanding was the lime1 was specifically designed as a sensible subset of generic that project like wasi-libc could use.

honestly speaking, i don't understand why "generic" and wasi should have different defaults.
is "generic" meant for web?

the intention of this PR is "do not enable extra features we ourselves (eg. libc) doesn't benefit from".

extended-const does benefit shared library builds (it allows data segments to express their offset without extra startup code).

it's true.
i'm not sure if extended-const is ubiquitous among non-web runtimes though.

@sunfishcode
Copy link
Member

Could you comment on the practical impact of this change? Which features in the wasi-libc build are you looking to disable? Or is there some other purpose here?

@yamt
Copy link
Contributor Author

yamt commented May 7, 2025

Could you comment on the practical impact of this change? Which features in the wasi-libc build are you looking to disable? Or is there some other purpose here?

reference-types makes some environment unhappy.
eg. bytecodealliance/wasm-micro-runtime#3977

@sunfishcode
Copy link
Member

i'm not sure if extended-const is ubiquitous among non-web runtimes though.

It is in some, it's behind a flag in others, and it's expected to be easy to implement for the rest. And it also happens to be shipping in all the web runtimes already. And, it enables significantly better dynamic libraries.

There's a tradeoff here, but unless we know of some significant burden this creates, I think it makes sense to keep the ecosystem moving forward, and leave extended-const enabled here.

yamt added a commit to yamt/wasi-libc that referenced this pull request May 13, 2025
My motivation is to allow -mcpu=lime1 build with LLVM 20.

Note that extended-const is a part of lime1.
https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1

cf. WebAssembly/wasi-sdk#527
@yamt
Copy link
Contributor Author

yamt commented May 13, 2025

i'm not sure if extended-const is ubiquitous among non-web runtimes though.

It is in some, it's behind a flag in others, and it's expected to be easy to implement for the rest. And it also happens to be shipping in all the web runtimes already. And, it enables significantly better dynamic libraries.

There's a tradeoff here, but unless we know of some significant burden this creates, I think it makes sense to keep the ecosystem moving forward, and leave extended-const enabled here.

ok.
i filed an issue for wamr bytecodealliance/wasm-micro-runtime#4272

sbc100 pushed a commit to WebAssembly/wasi-libc that referenced this pull request May 13, 2025
My motivation is to allow -mcpu=lime1 build with LLVM 20.

Note that extended-const is a part of lime1.
https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1

cf. WebAssembly/wasi-sdk#527
@yamt yamt changed the title lime1 Add an option to specify CFLAGS for wasm features and make lime1 the default May 14, 2025
@yamt
Copy link
Contributor Author

yamt commented May 15, 2025

i filed llvm/llvm-project#140010 while testing this

@yamt yamt marked this pull request as ready for review May 15, 2025 06:48
yamt added 3 commits May 20, 2025 14:37
…default

Add a cmake option WASI_SDK_CPU_CFLAGS to specify CFLAGS to
control wasm features to enable/disable.
Make the default `-mcpu=lime1`.

Comparing to the default "generic" target of the recent llvm,
this effectively:

* disables reference-types and bulk-memory (enable their
  partial counterparts instead)

* enables extended-const

Note: as of writing this, a few popular runtimes, including wasm3 and
wasm-micro-runtime, don't support extented-const yet.

Note: regardless of this, wasi-libc enables necessary features for
certain files. (bulk-memory and exception-handling)

cf. WebAssembly#525

References:
https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md
bytecodealliance/wasm-micro-runtime#4272
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

Successfully merging this pull request may close these issues.

3 participants