|
13 | 13 | # See the License for the specific language governing permissions and |
14 | 14 | # limitations under the License. |
15 | 15 |
|
16 | | -load("@rules_cc//cc:defs.bzl", "cc_binary") |
17 | | - |
18 | | -def _wasm_cc_transition_impl(settings, attr): |
19 | | - return { |
20 | | - "//command_line_option:cpu": "wasm32", |
21 | | - "//command_line_option:crosstool_top": "@proxy_wasm_cpp_sdk//toolchain:emscripten", |
22 | | - |
23 | | - # Overriding copt/cxxopt/linkopt to prevent sanitizers/coverage options leak |
24 | | - # into Wasm build configuration |
25 | | - "//command_line_option:copt": [], |
26 | | - "//command_line_option:cxxopt": [], |
27 | | - "//command_line_option:linkopt": [], |
28 | | - "//command_line_option:collect_code_coverage": "false", |
29 | | - "//command_line_option:fission": "no", |
30 | | - } |
31 | | - |
32 | | -wasm_cc_transition = transition( |
33 | | - implementation = _wasm_cc_transition_impl, |
34 | | - inputs = [], |
35 | | - outputs = [ |
36 | | - "//command_line_option:cpu", |
37 | | - "//command_line_option:crosstool_top", |
38 | | - "//command_line_option:copt", |
39 | | - "//command_line_option:cxxopt", |
40 | | - "//command_line_option:fission", |
41 | | - "//command_line_option:linkopt", |
42 | | - "//command_line_option:collect_code_coverage", |
43 | | - ], |
44 | | -) |
45 | | - |
46 | | -def wasm_binary_impl(ctx): |
47 | | - out = ctx.actions.declare_file(ctx.label.name) |
48 | | - ctx.actions.run( |
49 | | - executable = "cp", |
50 | | - arguments = [ctx.files.binary[0].path, out.path], |
51 | | - outputs = [out], |
52 | | - inputs = ctx.files.binary, |
53 | | - ) |
54 | | - |
55 | | - return [DefaultInfo(files = depset([out]), runfiles = ctx.runfiles([out]))] |
56 | | - |
57 | | -def _wasm_attrs(transition): |
58 | | - return { |
59 | | - "binary": attr.label(mandatory = True, cfg = transition), |
60 | | - "_whitelist_function_transition": attr.label(default = "@bazel_tools//tools/whitelists/function_transition_whitelist"), |
61 | | - } |
62 | | - |
63 | | -# Wasm binary rule implementation. |
64 | | -# This copies the binary specified in binary attribute in Wasm configuration to |
65 | | -# target configuration, so a binary in non-Wasm configuration can depend on them. |
66 | | -wasm_cc_binary_rule = rule( |
67 | | - implementation = wasm_binary_impl, |
68 | | - attrs = _wasm_attrs(wasm_cc_transition), |
69 | | -) |
70 | | - |
71 | 16 | def wasm_cc_binary(**kwargs): |
72 | | - fail("`wasm_cc_binary` is deprecated. Please use `proxy_wasm_cc_binary`.") |
73 | | - |
74 | | -def proxy_wasm_cc_binary(name, additional_linker_inputs = [], linkopts = [], tags = [], deps = [], **kwargs): |
75 | | - wasm_name = "_wasm_" + name |
76 | | - kwargs.setdefault("visibility", ["//visibility:public"]) |
77 | | - cc_binary( |
78 | | - name = wasm_name, |
79 | | - additional_linker_inputs = additional_linker_inputs + [ |
80 | | - "@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_js", |
81 | | - ], |
82 | | - linkopts = linkopts + [ |
83 | | - "--no-entry", |
84 | | - "--js-library=$(location @proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_js)", |
85 | | - "-sSTANDALONE_WASM", |
86 | | - "-sEXPORTED_FUNCTIONS=_malloc", |
87 | | - ], |
88 | | - # Adding manual tag it won't be built in non-Wasm (e.g. x86_64 config) |
89 | | - # when an wildcard is specified, but it will be built in Wasm configuration |
90 | | - # when the wasm_binary below is built. |
91 | | - tags = tags + [ |
92 | | - "manual", |
93 | | - ], |
94 | | - deps = deps + [ |
95 | | - "@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics", |
96 | | - ], |
97 | | - **kwargs |
98 | | - ) |
| 17 | + fail("`wasm_cc_binary` is deprecated. Please use `proxy_wasm_cc_binary` from `@proxy_wasm_cpp_sdk//bazel:defs.bzl`.") |
99 | 18 |
|
100 | | - wasm_cc_binary_rule( |
101 | | - name = name, |
102 | | - binary = ":" + wasm_name, |
103 | | - tags = tags, |
104 | | - ) |
| 19 | +def proxy_wasm_cc_binary(**kwargs): |
| 20 | + fail("Please use `proxy_wasm_cc_binary` from `@proxy_wasm_cpp_sdk//bazel:defs.bzl`.") |
0 commit comments