Skip to content

Commit 459f7c1

Browse files
authored
Update bazel readme (#774)
* Update bazel/README.md * Add deps instantiation to readme * Add bazelrc explanations to readme * Note the preferred way of using bazel emsdk
1 parent c1589b5 commit 459f7c1

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

bazel/README.md

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,34 @@
22

33
## Setup Instructions
44

5-
1. Merge the `WORKSPACE` file in with your own at the root of your bazel
6-
directory structure. If you don't have one, simply copy the file.
7-
2. Merge the `bazelrc` file in with your `.bazelrc` file at the root of your
8-
bazel directory structure. If you don't have one, simply copy the file and
9-
rename it to `.bazelrc`. (Note the `.`)
10-
3. Copy the `emscripten_toolchain` folder along with its contents to the root of
11-
your bazel directory.
12-
13-
Your directory structure should look like this:
5+
In `WORKSPACE` file, put:
146
```
15-
bazel_root/
16-
├── .bazelrc
17-
├── WORKSPACE
18-
├── emscripten_toolchain/
19-
│ ├── BUILD.bazel
20-
│ ├── builddefs.bzl
21-
│ ├── crosstool.bzl
22-
│ ├── emar.sh
23-
│ ├── emcc.sh
24-
│ ├── emcc_link.sh
25-
│ ├── emscripten.BUILD
26-
│ ├── emscripten_config
27-
│ ├── env.sh
28-
│ ├── link_wrapper.py
29-
│ ├── wasm_binary.py
30-
│ ├── wasm_cc_binary.bzl
31-
│ ├── wasm_rules.bzl
32-
├── your_project_folder/
33-
│ ├── your_project.file
7+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
8+
http_archive(
9+
name = "emsdk",
10+
strip_prefix = "emsdk-c1589b55641787d55d53e883852035beea9aec3f/bazel",
11+
url = "https://github.com/emscripten-core/emsdk/archive/c1589b55641787d55d53e883852035beea9aec3f.tar.gz",
12+
sha256 = "7a58a9996b113d3e0675df30b5f17e28aa47de2e684a844f05394fe2f6f12e8e",
13+
)
14+
15+
load("@emsdk//:deps.bzl", emsdk_deps = "deps")
16+
emsdk_deps()
17+
18+
load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")
19+
emsdk_emscripten_deps()
3420
```
3521

3622
## Building
3723

3824
### Using --config=wasm
25+
26+
Put the following lines into your `.bazelrc`:
27+
```
28+
build:wasm --crosstool_top=//emscripten_toolchain:everything
29+
build:wasm --cpu=wasm
30+
build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
31+
```
32+
3933
Simply pass `--config=wasm` when building a normal `cc_binary`. The result of
4034
this build will be a tar archive containing any files produced by emscripten.
4135

@@ -44,7 +38,7 @@ First, write a new rule wrapping your `cc_binary`.
4438

4539
```
4640
load("@rules_cc//cc:defs.bzl", "cc_binary")
47-
load("//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
41+
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
4842
4943
cc_binary(
5044
name = "hello-world",
@@ -61,3 +55,7 @@ Now you can run `bazel build :hello-world-wasm`. The result of this build will
6155
be the individual files produced by emscripten. Note that some of these files
6256
may be empty. This is because bazel has no concept of optional outputs for
6357
rules.
58+
59+
`wasm_cc_binary` uses transition to use emscripten toolchain on `cc_target`
60+
and all of its dependencies, and does not require amending `.bazelrc`. This
61+
is the preferred way, since it also unpacks the resulting tarball.

0 commit comments

Comments
 (0)