2
2
3
3
## Setup Instructions
4
4
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:
14
6
```
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()
34
20
```
35
21
36
22
## Building
37
23
38
24
### 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
+
39
33
Simply pass ` --config=wasm ` when building a normal ` cc_binary ` . The result of
40
34
this build will be a tar archive containing any files produced by emscripten.
41
35
@@ -44,7 +38,7 @@ First, write a new rule wrapping your `cc_binary`.
44
38
45
39
```
46
40
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")
48
42
49
43
cc_binary(
50
44
name = "hello-world",
@@ -61,3 +55,7 @@ Now you can run `bazel build :hello-world-wasm`. The result of this build will
61
55
be the individual files produced by emscripten. Note that some of these files
62
56
may be empty. This is because bazel has no concept of optional outputs for
63
57
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