Skip to content

Missing emcc.py when building using bazel. #1540

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
Sero1000 opened this issue Mar 22, 2025 · 5 comments
Open

Missing emcc.py when building using bazel. #1540

Sero1000 opened this issue Mar 22, 2025 · 5 comments

Comments

@Sero1000
Copy link

I am trying to build a hello world application following bazels guide using bazels toolchain. I have followed the guide here. I have added a the toolchain in a WORKSPACE.bzlmod file, created a .bazelrc and added a new target named hello-world-wasm like this:

load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")

cc_binary(
    name = "hello-world",
    srcs = ["hello-world.cc"],
)

wasm_cc_binary(
    name = "hello-world-wasm",
    cc_target = "hello-world"
)

WORKSPACE.bzlmod

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
    name = "emsdk",
    remote = "https://github.com/emscripten-core/emsdk.git",
    tag = "3.1.64",
    strip_prefix = "bazel",
)

load("@emsdk//:deps.bzl", emsdk_deps = "deps")
emsdk_deps()

load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")
emsdk_emscripten_deps(emscripten_version = "3.1.64")

load("@emsdk//:toolchains.bzl", "register_emscripten_toolchains")
register_emscripten_toolchains()

I am running the build using this command line :
bazel build //main:hello-world-wasm --sandbox_debug --enable_workspace

ERROR :
/Applications/Xcode.app/Contents/Developer/usr/bin/python3: can't open file '/private/var/tmp/_bazel_smirzakhanyan/5ccbffad594df6a7f12c0c7207e57fcd/sandbox/darwin-sandbox/1/execroot/_main/external/emscripten_bin_mac_arm64/emscripten/emcc.py': [Errno 2] No such file or directory

Indeed there is no emcc.py file in the repo but there are references to it.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 24, 2025

emsdk.py should part of the archive file that downloaded and expanded by the emsdk_emscripten_deps step. Do you have any files under /private/var/tmp/_bazel_smirzakhanyan/5ccbffad594df6a7f12c0c7207e57fcd/sandbox/darwin-sandbox/1/execroot/_main/external/emscripten_bin_mac_arm64 ? It should contain emscripten as well as llvm and binaryen builds.

Do things work better if you try the very latest version of emscripten? i.e. if you change the two version numbers to 4.0.5?

@Sero1000
Copy link
Author

Sero1000 commented Mar 24, 2025

The folder emscripten_bin_mac_arm64 does not exist in that directory. I have it in ..../5ccbffad594df6a7f12c0c7207e57fcd/execroot/_main/exnternal/ .Trying version 4.0.5 gives the same error.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 24, 2025

Seems like something is fundamentally broken with the archives files and where they are expected to be expanded to.

I don't know enough about how emsdk_emscripten_deps works know where looks next. Perhaps @walkingeyerobot or @lravenclaw might have some clue?

@Sero1000
Copy link
Author

Update : I looked into it and it looks to be a sanboxing issue which should be enabled by default on my machine. I tried to run the build command with --spawn_strategy=local and it found the emcc.py file, but now I am getting another error.

ERROR: bazel_examples/cpp-tutorial/stage1/main/BUILD:3:10: Compiling main/hello-world.cc failed: undeclared inclusion(s) in rule '//main:hello-world':
this rule is missing dependency declarations for the following files included by 'main/hello-world.cc':
  'external/emscripten_bin_mac_arm64/emscripten/cache/sysroot/include/c++/v1/iostream'
  'external/emscripten_bin_mac_arm64/emscripten/cache/sysroot/include/c++/v1/__assert'
  'external/emscripten_bin_mac_arm64/emscripten/cache/sysroot/include/c++/v1/__assertion_handler'
  'external/emscripten_bin_mac_arm64/emscripten/cache/sysroot/include/c++/v1/__config'
  'external/emscripten_bin_mac_arm64/emscripten/cache/sysroot/include/c++/v1/__config_site'
  'external/emscripten_bin_mac_arm64/emscripten/cache/sysroot/include/c++/v1/__verbose_abort'
  'external/emscripten_bin_mac_arm64/emscripten/cache/sysroot/include/c++/v1/__availability'
  'external/emscripten_bin_mac_arm64/emscripten/cache/sysroot/include/c++/v1/version'
.....

@jfirebaugh
Copy link
Contributor

I encountered the same issue attempting to upgrade to Bazel 8. I believe this may be a bug in Bazel.

I created a minimal reproducer, and used that to bisect to a specific commit in Bazel that triggers the issue:

https://github.com/jfirebaugh/emscripten_bazel_8_bug

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