-
Notifications
You must be signed in to change notification settings - Fork 0
/
wasmer.bzl
87 lines (74 loc) · 2.18 KB
/
wasmer.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
"""
_linux_wasmer_build_file_contents = """
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_import")
cc_import(
name = "wasmer-c-api-lib",
static_library = "lib/libwasmer.a",
)
cc_library(
name = "wasmer-c-api",
visibility = ["//visibility:public"],
strip_include_prefix = "include",
defines = ["WASM_API_EXTERN=extern"],
hdrs = [
"include/wasm.h",
"include/wasmer.h",
"include/wasmer_wasm.h",
],
deps = [
":wasmer-c-api-lib",
],
)
"""
_windows_wasmer_build_file_contents = """
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_import")
cc_import(
name = "wasmer-c-api-lib",
static_library = "lib/wasmer.lib",
)
cc_library(
name = "wasmer-c-api",
visibility = ["//visibility:public"],
strip_include_prefix = "include",
defines = ["WASM_API_EXTERN=extern"],
linkopts = [
"-DEFAULTLIB:ws2_32",
"-DEFAULTLIB:Advapi32",
"-DEFAULTLIB:Userenv",
"-DEFAULTLIB:Bcrypt",
],
hdrs = [
"include/wasm.h",
"include/wasmer.h",
"include/wasmer_wasm.h",
],
deps = [
":wasmer-c-api-lib",
],
)
"""
def _wasmer_config(rctx, wasmer, args):
result = rctx.execute([wasmer, "config"] + args)
if result.return_code != 0:
fail("wasmer config failed (exit_code={}): {}".format(result.exit_code, result.stderr))
return result.stdout.strip()
def _wasmer_repo(rctx):
wasmer = rctx.which("wasmer")
if not wasmer:
fail("Cannot find 'wasmer' in PATH")
includedir = _wasmer_config(rctx, wasmer, ["--includedir"])
libdir = _wasmer_config(rctx, wasmer, ["--libdir"])
rctx.symlink(includedir, "include")
rctx.symlink(libdir, "lib")
build_file_contents = {
"linux": _linux_wasmer_build_file_contents,
"windows 10": _windows_wasmer_build_file_contents,
"windows server 2019": _windows_wasmer_build_file_contents,
}
if not rctx.os.name in build_file_contents:
fail("unsupported repository os: {}".format(rctx.os.name))
rctx.file("BUILD.bazel", content = build_file_contents[rctx.os.name], executable = False)
wasmer_repo = repository_rule(
implementation = _wasmer_repo,
)