James Kuszmaul | 27da814 | 2019-07-21 16:13:55 -0700 | [diff] [blame] | 1 | package(default_visibility = ["//visibility:public"]) |
| 2 | |
James Kuszmaul | 9a05bfd | 2019-08-03 17:03:38 -0700 | [diff] [blame^] | 3 | _minimum_fileset = [ |
| 4 | "emar.sh", |
| 5 | "emcc.sh", |
| 6 | "@emscripten_clang//:all", |
| 7 | "@emscripten_toolchain//:all", |
| 8 | "@nodejs//:bin/node", |
| 9 | ] |
| 10 | |
| 11 | filegroup( |
| 12 | name = "minimum_files", |
| 13 | srcs = _minimum_fileset, |
| 14 | ) |
| 15 | |
James Kuszmaul | 27da814 | 2019-07-21 16:13:55 -0700 | [diff] [blame] | 16 | filegroup( |
| 17 | name = "all", |
James Kuszmaul | 9a05bfd | 2019-08-03 17:03:38 -0700 | [diff] [blame^] | 18 | srcs = _minimum_fileset + [ |
James Kuszmaul | 27da814 | 2019-07-21 16:13:55 -0700 | [diff] [blame] | 19 | ":emscripten_cache_content", |
James Kuszmaul | 27da814 | 2019-07-21 16:13:55 -0700 | [diff] [blame] | 20 | ], |
| 21 | ) |
| 22 | |
James Kuszmaul | 9a05bfd | 2019-08-03 17:03:38 -0700 | [diff] [blame^] | 23 | # A list of all the cached libraries generad and used by emscripten. |
| 24 | _libs = \ |
| 25 | ["emscripten_cache/asmjs/" + lib for lib in [ |
| 26 | "generated_struct_info.json", |
| 27 | "libc.bc", |
| 28 | "libcompiler_rt.a", |
| 29 | "libc-wasm.bc", |
| 30 | "libpthreads_stub.bc", |
| 31 | "libhtml5.bc", |
| 32 | "libdlmalloc.bc", |
| 33 | "libal.bc", |
| 34 | "libc++_noexcept.a", |
| 35 | "libc++abi.bc", |
| 36 | "libgl-webgl2.bc", |
| 37 | "libgl.bc", |
| 38 | "libc-extras.bc", |
| 39 | ]] |
| 40 | |
James Kuszmaul | 27da814 | 2019-07-21 16:13:55 -0700 | [diff] [blame] | 41 | filegroup( |
| 42 | name = "emscripten_cache_content", |
James Kuszmaul | 9a05bfd | 2019-08-03 17:03:38 -0700 | [diff] [blame^] | 43 | srcs = glob(["emscripten_cache/**/*"]) + _libs, |
James Kuszmaul | 27da814 | 2019-07-21 16:13:55 -0700 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | cc_toolchain( |
| 47 | name = "cc_emscripten", |
| 48 | all_files = ":all", |
| 49 | compiler_files = ":all", |
| 50 | cpu = "web", |
| 51 | dwp_files = ":empty", |
| 52 | dynamic_runtime_libs = [":empty"], |
| 53 | linker_files = ":all", |
| 54 | objcopy_files = ":empty", |
| 55 | static_runtime_libs = [":empty"], |
| 56 | strip_files = ":empty", |
| 57 | supports_param_files = 0, |
| 58 | ) |
James Kuszmaul | 9a05bfd | 2019-08-03 17:03:38 -0700 | [diff] [blame^] | 59 | |
| 60 | # TODO(james): Currently, this gets built with the host configuration. |
| 61 | # Currently, that doesn't actually impact the build since there's nothing that |
| 62 | # affects how the genrule is run. However, that also means that changing |
| 63 | # the configuration (and thus the flags that may be passed to the C++ |
| 64 | # compiler) will not change how these cache files are generated. |
| 65 | genrule( |
| 66 | name = "gencache", |
| 67 | # Note that foo.o is just some arbitrary .o file. I had trouble getting |
| 68 | # emscripten to work properly when pointed at a literally empty file, but |
| 69 | # the exact contents of the .o aren't particularly important. |
| 70 | srcs = [":foo.o"], |
| 71 | outs = _libs, |
| 72 | cmd = "$(location gencache.sh) $(OUTS)", |
| 73 | tools = [ |
| 74 | ":gencache.sh", |
| 75 | ":minimum_files", |
| 76 | ], |
| 77 | ) |