Skip to content

Commit 8d1808e

Browse files
authored
feat: allow si module implementation linking to be configurable (#82)
1 parent 75cf289 commit 8d1808e

File tree

3 files changed

+80
-39
lines changed

3 files changed

+80
-39
lines changed

BUILD.bazel

+38-18
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,65 @@ filegroup(
2222

2323
cc_library(
2424
name = "ecsact_si_wasm",
25-
copts = copts,
26-
defines = [
27-
"ECSACTSI_WASM_API=",
28-
"ECSACT_DYNAMIC_API=",
29-
],
3025
hdrs = [":headers"],
31-
srcs = [":sources"],
26+
copts = copts,
3227
deps = [
33-
"@wasmer",
3428
"@ecsact_runtime//:common",
3529
"@ecsact_runtime//:dynamic",
30+
"@wasmer",
3631
],
3732
)
3833

34+
"""
35+
It is expected that users of this target are to set ECSACTSI_WASM_API* and ECSACT_DYNAMIC_API* macros for their configuration
36+
Example 1:
37+
```
3938
cc_library(
40-
name = "ecsact_si_wasm_dynamic_lat",
41-
copts = copts,
39+
name = "my_si_wasm_impl",
40+
deps = ["@ecsact_si_wasm//:implementation"],
4241
defines = [
42+
# Statically link the si_wasm api
4343
"ECSACTSI_WASM_API=",
44+
# Load the dynamic module at runtime
4445
"ECSACT_DYNAMIC_API_LOAD_AT_RUNTIME",
4546
],
46-
hdrs = [":headers"],
47+
)
48+
```
49+
50+
```
51+
Example 2:
52+
cc_library(
53+
name = "my_si_wasm_impl",
54+
deps = ["@ecsact_si_wasm//:implementation"],
55+
defines = [
56+
# Statically link the si_wasm api
57+
"ECSACTSI_WASM_API=",
58+
# Statically link dynamic module
59+
"ECSACT_DYNAMIC_API=",
60+
],
61+
)
62+
```
63+
"""
64+
65+
cc_library(
66+
name = "implementation",
4767
srcs = [":sources"],
68+
hdrs = [":headers"],
69+
copts = copts,
4870
deps = [
49-
"@wasmer",
50-
"@ecsact_runtime//:common",
51-
"@ecsact_runtime//:dynamic",
71+
":ecsact_si_wasm",
5272
],
5373
)
5474

5575
cc_library(
5676
name = "minst",
57-
copts = copts,
58-
hdrs = [
59-
"ecsact/wasm/detail/minst/minst.hh",
60-
],
6177
srcs = [
6278
"ecsact/wasm/detail/minst/minst.cc",
6379
],
80+
hdrs = [
81+
"ecsact/wasm/detail/minst/minst.hh",
82+
],
83+
copts = copts,
6484
deps = [
6585
":cpp_util",
6686
"@ecsact_runtime//:common",
@@ -70,6 +90,6 @@ cc_library(
7090

7191
cc_library(
7292
name = "cpp_util",
73-
copts = copts,
7493
hdrs = ["ecsact/wasm/detail/cpp_util.hh"],
94+
copts = copts,
7595
)

test/BUILD.bazel

+32-12
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,47 @@ package(default_visibility = [":__subpackages__"])
99

1010
exports_files(["test.cc"])
1111

12+
cc_library(
13+
name = "impl",
14+
srcs = [
15+
"@ecsact_si_wasm//:sources",
16+
],
17+
copts = copts,
18+
defines = [
19+
# Statically link the si_wasm api
20+
"ECSACTSI_WASM_API=",
21+
# Statically link dynamic module
22+
"ECSACT_DYNAMIC_API=",
23+
],
24+
deps = [
25+
"@ecsact_si_wasm",
26+
],
27+
)
28+
1229
cc_test(
1330
name = "minst_test",
1431
srcs = ["minst_test.cc"],
1532
args = ["ecsact_si_wasm_test/minst_test.wasm"],
1633
copts = copts,
17-
linkopts = linkopts,
18-
deps = ["@ecsact_si_wasm//:minst", "@bazel_tools//tools/cpp/runfiles"],
1934
data = [":minst_test_wasm"],
35+
linkopts = linkopts,
36+
deps = [
37+
"@bazel_tools//tools/cpp/runfiles",
38+
"@ecsact_si_wasm//:minst",
39+
],
2040
)
2141

2242
cc_binary(
2343
name = "minst_test_wasm_cc",
2444
srcs = ["minst_test_wasm.cc"],
45+
features = [
46+
"-exceptions",
47+
],
2548
# copts = copts,
2649
linkopts = [
2750
"-sERROR_ON_UNDEFINED_SYMBOLS=0",
2851
"--no-entry",
2952
],
30-
features = [
31-
"-exceptions",
32-
],
3353
linkshared = True,
3454
tags = ["manual"],
3555
deps = [
@@ -67,16 +87,16 @@ ecsact_entt_runtime(
6787
name = "{}__system_impl".format(wasi_test),
6888
srcs = ["wasi_test_{}.cc".format(wasi_test)],
6989
copts = copts,
70-
linkopts = [
71-
"-sERROR_ON_UNDEFINED_SYMBOLS=0",
72-
"--no-entry",
73-
],
7490
features = [
7591
"wasm_no_entry",
7692
"-wasm_warnings_as_errors",
7793
"-wasm_error_on_undefined_symbols",
7894
"-exceptions",
7995
],
96+
linkopts = [
97+
"-sERROR_ON_UNDEFINED_SYMBOLS=0",
98+
"--no-entry",
99+
],
80100
linkshared = True,
81101
tags = ["manual"],
82102
deps = [
@@ -103,20 +123,20 @@ ecsact_entt_runtime(
103123
"wasi_test.cc",
104124
],
105125
copts = copts,
106-
linkopts = linkopts,
107126
data = [
108127
":{}__system_impl.wasm".format(wasi_test),
109128
"wasi_test_file.txt",
110129
],
111130
defines = ["ECSACTSI_WASM_API="],
131+
linkopts = linkopts,
112132
deps = [
133+
":impl",
113134
":wasi_test_runtime",
114135
"@ecsact_runtime//:core",
115136
"@ecsact_runtime//:dynamic",
116137
"@ecsact_runtime//:meta",
117138
"@magic_enum",
118139
"@wasmer",
119-
"@ecsact_si_wasm",
120140
],
121141
) for wasi_test in _WASI_TESTS]
122142

@@ -128,12 +148,12 @@ ecsact_entt_runtime(
128148
"$(location :{}__system_impl.wasm)".format(wasi_test),
129149
],
130150
copts = copts,
131-
linkopts = linkopts,
132151
data = [
133152
":{}__system_impl.wasm".format(wasi_test),
134153
":{}__wasi".format(wasi_test),
135154
"wasi_test_file.txt",
136155
],
156+
linkopts = linkopts,
137157
) for wasi_test in _WASI_TESTS]
138158

139159
refresh_compile_commands(

test/example/BUILD.bazel

+10-9
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ cc_binary(
2020
"system_impls.cc",
2121
],
2222
copts = copts,
23+
features = [
24+
"-exceptions",
25+
],
2326
linkopts = [
2427
"-sERROR_ON_UNDEFINED_SYMBOLS=0",
2528
"--no-entry",
2629
],
27-
features = [
28-
"-exceptions",
29-
],
3030
linkshared = True,
3131
tags = ["manual"],
3232
deps = [
@@ -64,27 +64,28 @@ cc_test(
6464
name = "wasmer_example",
6565
srcs = [
6666
"example.cc",
67+
"@ecsact_si_wasm//:sources",
6768
],
6869
args = [
6970
"$(location :system_impls.wasm)",
7071
],
7172
copts = copts,
72-
linkopts = linkopts,
73+
data = [
74+
":system_impls.wasm",
75+
],
7376
defines = [
7477
"ECSACTSI_WASM_API=",
7578
"ECSACT_CORE_API=",
7679
],
80+
linkopts = linkopts,
7781
deps = [
7882
":runtime",
79-
"@ecsact_si_wasm//:minst",
8083
"@ecsact_runtime//:core",
8184
"@ecsact_runtime//:dynamic",
8285
"@ecsact_runtime//:meta",
86+
"@ecsact_si_wasm",
87+
"@ecsact_si_wasm//:minst",
8388
"@magic_enum",
8489
"@wasmer",
85-
"@ecsact_si_wasm",
86-
],
87-
data = [
88-
":system_impls.wasm",
8990
],
9091
)

0 commit comments

Comments
 (0)