Skip to content

Commit 61c15f6

Browse files
committed
Rename lib OutputKind to testlib
Since it's only used for tests. I also moved the definition of the OutputKind type into build_info.py to go next to BuildType and BuildTarget.
1 parent 321a992 commit 61c15f6

7 files changed

Lines changed: 23 additions & 13 deletions

File tree

spy/backend/c/cbackend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def get_merged_build_info(self) -> BuildInfo:
206206
def write_build_script(self) -> None:
207207
assert self.cfiles != [], "call .cwrite() first"
208208
wasm_exports = []
209-
if self.config.target == "wasi" and self.config.kind == "lib":
209+
if self.config.target == "wasi" and self.config.kind == "testlib":
210210
wasm_exports = self.get_wasm_exports()
211211

212212
extra = self.get_merged_build_info()

spy/build/build_info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
BuildTarget = Literal["native", "wasi", "emscripten"]
55
BuildType = Literal["release", "debug"]
6+
OutputKind = Literal["exe", "testlib", "py-cffi"]
67

78

89
@dataclass

spy/build/config.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from typing import Literal, Optional
66

77
import spy.libspy
8-
from spy.build.build_info import BuildTarget, BuildType
8+
from spy.build.build_info import BuildTarget, BuildType, OutputKind
99
from spy.build.flags import get_cc, get_cflags, get_ldflags, get_libdir
10+
from spy.errors import WIP
1011

11-
OutputKind = Literal["exe", "lib", "py-cffi"]
1212
GCOption = Literal["none", "bdwgc"]
1313

1414

@@ -22,6 +22,12 @@ class BuildConfig:
2222
gc: GCOption = "none"
2323
static: bool = False
2424

25+
def __post_init__(self) -> None:
26+
if self.kind == "testlib" and self.target not in ("wasi", "emscripten"):
27+
raise WIP(
28+
"--output-kind=testlib works only for wasi and emscripten targets"
29+
)
30+
2531

2632
# ======= CFLAGS and LDFLAGS logic =======
2733

@@ -61,8 +67,8 @@ def __init__(self, config: BuildConfig):
6167
self.ldflags += get_ldflags(flags_target, config.build_type)
6268

6369
libdir = get_libdir(flags_target, config.build_type)
64-
if config.target == "wasi" and config.kind == "lib":
65-
# WASM libs are mostly used by tests: in this case we want to make sure to
70+
if config.target == "wasi" and config.kind == "testlib":
71+
# WASM testlibs are used by tests: in this case we want to make sure to
6672
# include the whole libspy.a, so that helper functions such as spy_str_alloc
6773
# are always available.
6874
#
@@ -89,7 +95,7 @@ def __init__(self, config: BuildConfig):
8995

9096
elif config.target == "wasi":
9197
self.ext = ".wasm"
92-
if config.kind == "lib":
98+
if config.kind == "testlib":
9399
self.ldflags += ["-mexec-model=reactor"]
94100

95101
elif config.target == "emscripten":

spy/build/flags.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
python -m spy.build.flags --ldflags --target=wasi --build-type=release
88
python -m spy.build.flags --libdir --target=wasi --build-type=debug
99
python -m spy.build.flags --cc --target=wasi
10+
python -m spy.build.flags --cflags --target=wasi --output-kind=testlib
1011
"""
1112

1213
import argparse
@@ -15,12 +16,12 @@
1516
from typing import Optional
1617

1718
import spy
19+
from spy.build.build_info import BuildType
1820

1921
_LIBSPY = spy.ROOT.join("libspy")
2022
_INCLUDE = _LIBSPY.join("include")
2123
_BUILD = _LIBSPY.join("build")
2224

23-
BuildType = str # "release" | "debug"
2425

2526
# Base CFLAGS shared by all targets (mirrors spy/libspy/Makefile)
2627
_BASE_CFLAGS: list[str] = [

spy/build/ninja.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class NinjaWriter:
3838

3939
def __init__(self, config: BuildConfig, build_dir: py.path.local) -> None:
4040
# for now, we support only some combinations of target/kind
41-
if config.kind == "lib":
41+
if config.kind == "testlib":
4242
if config.target not in ("wasi", "emscripten"):
4343
raise WIP(
44-
"--output-kind=lib works only for wasi and emscripten targets"
44+
"--output-kind=testlib works only for wasi and emscripten targets"
4545
)
4646
self.config = config
4747
self.build_dir = build_dir
@@ -60,7 +60,7 @@ def write(
6060
) -> None:
6161
comp = CompilerConfig(self.config)
6262
self.out = basename + comp.ext
63-
if self.config.kind == "lib":
63+
if self.config.kind == "testlib":
6464
comp.ldflags += [f"-Wl,--export={name}" for name in wasm_exports]
6565
for d in extra_include_dirs:
6666
comp.cflags += ["-I", d]

spy/tests/support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def compile(
226226
if self.backend == "C":
227227
config = BuildConfig(
228228
target="wasi",
229-
kind="lib",
229+
kind="testlib",
230230
build_type="debug",
231231
opt_level=self.OPT_LEVEL,
232232
)
@@ -370,7 +370,7 @@ def init(self, tmpdir):
370370
self.tmpdir = tmpdir
371371
# NOTE: target is overwritten by TestLLWasm.init_llwasm
372372
self.target = "wasi"
373-
self.kind = "lib"
373+
self.kind = "testlib"
374374
self.build_dir = self.tmpdir.join("build").ensure(dir=True)
375375

376376
def write(self, src: str) -> py.path.local:

spy/tests/test_backend_c.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def compile_until_CBackend(self, vm: SPyVM, src: str) -> CBackend:
3434
vm.import_(modname)
3535
vm.redshift(error_mode="eager")
3636
builddir = self.tmpdir.join("build").ensure(dir=True)
37-
config = BuildConfig(target="wasi", kind="lib", build_type="debug", opt_level=0)
37+
config = BuildConfig(
38+
target="wasi", kind="testlib", build_type="debug", opt_level=0
39+
)
3840
backend = CBackend(vm, modname, config, builddir, dump_c=False)
3941
return backend
4042

0 commit comments

Comments
 (0)