/
BUILD.bazel
137 lines (127 loc) · 3.05 KB
/
BUILD.bazel
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
load("@rules_cc//cc:defs.bzl", "cc_library")
load(
"@rules_haskell//haskell:defs.bzl",
"haskell_library",
"haskell_test",
)
load(
"//tests:analysis_tests.bzl",
"dynamic_libraries_in_runfiles_test",
)
load("//tests:inline_tests.bzl", "sh_inline_test")
# test whether `linkstatic` works as expected
package(default_testonly = 1)
cc_library(
name = "c-lib",
srcs = ["c-lib.c"],
)
haskell_library(
name = "HsLib",
srcs = ["HsLib.hs"],
deps = [
"//tests/hackage:base",
],
)
haskell_test(
name = "binary-static",
srcs = ["Main.hs"],
linkstatic = True,
deps = [
":HsLib",
":c-lib",
"//tests/hackage:base",
],
)
haskell_test(
name = "binary-dynamic",
srcs = ["Main.hs"],
linkstatic = False,
deps = [
":HsLib",
":c-lib",
"//tests/hackage:base",
],
)
dynamic_libraries_in_runfiles_test(
name = "dynamic-runfiles-test",
libs = [
":HsLib",
":c-lib",
"//tests/hackage:base",
],
tags = ["dont_test_on_windows"],
target_under_test = ":binary-dynamic",
)
config_setting(
name = "debug_build",
values = {
"compilation_mode": "dbg",
},
)
# Ensure that linkstatic=True only links to static library targets.
sh_inline_test(
name = "test-binary-static-symbols",
size = "small",
args = [
"$(rootpath :binary-static)",
],
data = [
":binary-static",
],
script = """
set -eo pipefail
binary="$1"
# Symbols are prefixed with underscore on macOS but not on Linux.
if nm -u "$binary" | grep -q "\\<_\\?value"; then
echo "C library dependency not linked statically: ${binary}"
exit 1
fi
if nm -u "$binary" | grep -q HsLib_value_closure; then
echo "Haskell library dependency not linked statically ${binary}"
exit 1
fi
""",
tags = ["dont_test_on_windows"],
)
# Ensure that linkstatic=False only links to dynamic library targets.
sh_inline_test(
name = "test-binary-dynamic-symbols",
size = "small",
args = [
"$(rootpath :binary-dynamic)",
] + select({
":debug_build": ["dbg"],
"//conditions:default": ["rls"],
}),
data = [
":binary-dynamic",
],
script = """
set -eo pipefail
binary="$1"
mode="$2"
if [[ $mode = dbg ]]; then
# Skip test in debug builds. Debug mode forces static linking.
exit 0
fi
# Symbols are prefixed with underscore on macOS but not on Linux.
if ! nm -u "$binary" | grep -q "\\<_\\?value"; then
echo "C library dependency not linked dynamically"
exit 1
fi
if ! nm -u "$binary" | grep -q HsLib_value_closure; then
echo "Haskell library dependency not linked dynamically"
exit 1
fi
""",
tags = ["dont_test_on_windows"],
)
test_suite(
name = "binary-linkstatic-flag",
tags = ["dont_test_on_windows"],
tests = [
":test-binary-dynamic-symbols",
":test-binary-static-symbols",
],
visibility = ["//visibility:public"],
)