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

Package preload files for wasm #3613

Closed
jingkaimori opened this issue Apr 9, 2023 · 2 comments
Closed

Package preload files for wasm #3613

jingkaimori opened this issue Apr 9, 2023 · 2 comments

Comments

@jingkaimori
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Some wasm program needs local asset files when starting. Emscripten provides a 'preload' mechanism to package these file into a .data package. XMake should make this kind of package from the list of install file.

Describe the solution you'd like

target("wasmapp") do
    set_kind("binary")
    add_installfiles("assets/as_1.md")
    add_installfiles("assets/as_2.md", {prefixdir = "doc"})
    add_installfiles("assets/(nest/as_3.md)", {prefixdir = "doc"})
end
emcc wasmapp.cpp -o wasmapp.html --preload-file assets/as_1.md --preload-file assets/as_2@doc/as_2.md--preload-file assets/nest/as_3@doc/nest/as_3.md

Describe alternatives you've considered

No response

Additional context

Usage of package arg of emcc is documented here.

@waruqi waruqi added this to the v2.7.9 milestone Apr 9, 2023
@waruqi
Copy link
Member

waruqi commented Apr 10, 2023

We should not use add_installfiles, it only for installation. xmake install

but --preload-file is only for building stage.

you can use

target("wasmapp") do
    set_kind("binary")
    add_ldflags({"--preload-file", "src/xxx.md"}, {expand = false, force = true})
    add_ldflags({"--preload-file", "src/xxx2.md"}, {expand = false, force = true})
end

waruqi added a commit that referenced this issue Apr 10, 2023
@waruqi
Copy link
Member

waruqi commented Apr 10, 2023

or you can try this on dev branch xmake update -s dev

target("test5")
    set_kind("binary")
    add_files("src/*.cpp")
    add_values("wasm.preloadfiles", "src/xxx.md")
    add_values("wasm.preloadfiles", "src/xxx2.md")

@waruqi waruqi closed this as completed Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants