Repository navigation
Expand file tree
/
Copy pathwscript
More file actions
81 lines (63 loc) · 2.74 KB
/
Copy pathwscript
File metadata and controls
81 lines (63 loc) · 2.74 KB
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
#
# Beep — build rules for a Pebble app written completely in Zig.
#
# Instead of compiling C from src/c/, we compile Zig source files to ARM
# objects (matching the emery/obelix ABI) and hand the resulting .o files to
# the Pebble SDK's normal link step (pbl_build), which links them against
# libpebble and the generated app linker script to produce the .pbw.
#
import os.path
top = '.'
out = 'build'
# Path to the Zig compiler. Override with the ZIG environment variable.
ZIG = os.environ.get('ZIG', '/home/kanna/.local/zig/zig')
# Emery apps are Cortex-M3, Thumb, soft-float, position independent (-fPIE on
# the C side -> -fPIC for the relocatable Zig object). Unwind tables are
# disabled so we don't pull in libgcc's C++ unwinder.
ZIG_FLAGS = [
'build-obj',
'-target', 'thumb-freestanding-eabi',
'-mcpu', 'cortex_m3',
'-fPIC',
'-fno-unwind-tables',
'-O', 'ReleaseSmall',
]
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
ctx.load('pebble_sdk')
ctx.env.ZIG = ZIG
def _zig_object(ctx, root_zig, out_name):
"""Compile `root_zig` (+ the shared pebble module) into a single ARM .o for
the current platform, and return the resulting build Node."""
pebble_mod = ctx.path.find_node('src/pebble.zig')
root_node = ctx.path.find_node(root_zig)
obj = ctx.path.get_bld().make_node('{}/{}'.format(ctx.env.BUILD_DIR, out_name))
# Global flags MUST come before the -M module declarations, otherwise Zig
# ignores -target and builds a host object.
rule = ('${ZIG} ' + ' '.join(ZIG_FLAGS) +
' -femit-bin=${TGT}'
' --dep pebble -Mroot=${SRC[0]} -Mpebble=${SRC[1]}')
ctx(rule=rule, source=[root_node, pebble_mod], target=obj)
return obj
def build(ctx):
ctx.load('pebble_sdk')
build_worker = os.path.exists('worker_src')
binaries = []
cached_env = ctx.env
for platform in ctx.env.TARGET_PLATFORMS:
ctx.env = ctx.all_envs[platform]
ctx.set_group(ctx.env.PLATFORM_NAME)
app_obj = _zig_object(ctx, 'src/main.zig', 'zig-app.o')
app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
ctx.pbl_build(source=[app_obj], target=app_elf, bin_type='app')
if build_worker:
wkr_obj = _zig_object(ctx, 'worker_src/worker.zig', 'zig-worker.o')
worker_elf = '{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR)
ctx.pbl_build(source=[wkr_obj], target=worker_elf, bin_type='worker')
binaries.append({'platform': platform, 'app_elf': app_elf, 'worker_elf': worker_elf})
else:
binaries.append({'platform': platform, 'app_elf': app_elf})
ctx.env = cached_env
ctx.set_group('bundle')
ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob(['src/pkjs/**/*.js']))