Skip to content

Improve bazel example #776

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: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ emsdk_emscripten_deps()

Put the following lines into your `.bazelrc`:
```
build:wasm --crosstool_top=//emscripten_toolchain:everything
build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug.

build:wasm --cpu=wasm
build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
```

Simply pass `--config=wasm` when building a normal `cc_binary`. The result of
this build will be a tar archive containing any files produced by emscripten.
Simply pass `--config=wasm` when building a normal `cc_binary`, e.g.
```
bazel build --config=wasm :hello-world
```
The result of this build will be a tar archive containing any files produced by emscripten.

### Using wasm_cc_binary
First, write a new rule wrapping your `cc_binary`.
Expand Down
3 changes: 3 additions & 0 deletions bazel/test_external/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without these, the example would not work for :hello-world.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok for the example to not work with --config=wasm right out of the box; we'd rather promote the use of wasm_cc_binary as it produces more useful output anyway. Also, the readme covers adding the appropriate lines to your own .bazelrc file, which would enable --config=wasm builds to function. The big thing here I want to avoid is having this file be identical to bazel/bazelrc and having to keep them both in sync.

build:wasm --cpu=wasm
build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
1 change: 1 addition & 0 deletions bazel/test_external/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*