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

compile wams64 using bazel mode #1362

Closed
phoenix20162016 opened this issue Mar 28, 2024 · 4 comments · Fixed by #1405
Closed

compile wams64 using bazel mode #1362

phoenix20162016 opened this issue Mar 28, 2024 · 4 comments · Fixed by #1405

Comments

@phoenix20162016
Copy link

in default bazel config, the build env is under 32bit mode, how can i switch to 64bit mode

@sbc100
Copy link
Collaborator

sbc100 commented Mar 28, 2024

To build for wasm64 you can add -sMEMORY64 to you compile and link commands.

@phoenix20162016
Copy link
Author

phoenix20162016 commented Mar 28, 2024

image
@sbc100 follows your suggestion,another error occurs, the following is my bazel configuration
image

in the fold of the compiler tools, the wasm64-emscripten dir really does not exist

@sbc100
Copy link
Collaborator

sbc100 commented Mar 28, 2024

I see, yes we don't currently wasm64 versions of any core libraries in the bazel toolchain. I think this is the same as #807. Perhaps we can close this and continue the discussion there?

@sbc100 sbc100 closed this as completed Mar 28, 2024
@wzheng21
Copy link

wzheng21 commented May 4, 2024

@phoenix20162016 I had the same problem as yours. For whoever having similar issues, I had to patch emsdk setting FROZEN_CACHE = False in config.py, then the issue becomes read-only blabla error, basically indicating emscripten tries to compile libraries and writes into a temporary cache folder but failed.

This of course would fail, due to bazel's idea of keeping builds hermitian. The following are the two different workarounds I tested that worked:

  1. Disable bazel sandbox mode. Just specify --spawn_strategy=local. Be careful when using this, especially if this is not a toy project
  2. Don't play with sandbox, but specify --action_env=EM_CACHE=~/.cache/emscripten_cache. When FROZEN_CACHE is False, emscripten will try to write to ~/.emscripten_cache, which will definitely fail in bazel sandbox mode due to permissions. Writing to ~/.cache folder, however, is allowed.

Hope this is helpful for anyone getting stuck with this issue.

sbc100 pushed a commit that referenced this issue Jul 1, 2024
This is a working solution for generating a separate Emscripten cache.
Note that this requires an additional entry in the workspace as follows:
```starlark
load("@emsdk//:emscripten_cache.bzl", emsdk_emscripten_cache = "emscripten_cache")
emsdk_emscripten_cache()
```
When used like this, the default Emscripten cache will be used. However,
if the entry is as follows:
```starlark
load("@emsdk//:emscripten_cache.bzl", emsdk_emscripten_cache = "emscripten_cache")
emsdk_emscripten_cache(flags = ["--lto"])
```
Then embuilder will be called to build all system libraries and ports
(i.e., the `ALL` option to embuilder) with the LTO option enabled. This
can take awhile, so I have also made possible to specify which libraries
you want to build explicitly:
```starlark
load("@emsdk//:emscripten_cache.bzl", emsdk_emscripten_cache = "emscripten_cache")
emsdk_emscripten_cache(
    flags = ["--lto"],
    libraries = [
        "crtbegin",
        "libprintf_long_double-debug",
        "libstubs-debug",
        "libnoexit",
        "libc-debug",
        "libdlmalloc",
        "libcompiler_rt",
        "libc++-noexcept",
        "libc++abi-debug-noexcept",
        "libsockets"
    ]
)
```

Resolves #807, resolves #971, resolves #1099, resolves #1362, resolves
#1401
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 a pull request may close this issue.

3 participants