-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
101 lines (86 loc) · 3.17 KB
/
Makefile
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
CWD := $(shell pwd)
OS := $(shell uname -s)
LIBS = lib/ameba lib/clang
WGPU_ARTIFACTS := vendor/webgpu.h vendor/wgpu.h
default: all
lint: shards
bin/ameba
crystal tool format -e src/lib-wgpu.cr --check
.PHONY: lint
test:
crystal spec
.PHONY: test
clean:
rm -f examples/headless
rm -f examples/*.dwarf
rm -rf lib
.PHONY: clean
all: vendor-libs shards
.PHONY: all
src/lib-wgpu.cr: lib/clang/bin/c2cr ${WGPU_ARTIFACTS}
@echo "# AUTOGENERATED: DO NOT EDIT!" > src/lib-wgpu.cr
@echo "@[Link(ldflags: \"-L#{__DIR__}/../bin/libs -lwgpu_native\")]" >> src/lib-wgpu.cr
lib/clang/bin/c2cr -Ivendor webgpu.h --remove-enum-prefix=WGPU >> src/lib-wgpu.cr
lib/clang/bin/c2cr -Ivendor wgpu.h --remove-enum-prefix=WGPU >>
@echo "Remember to follow instructions in src/lib-wgpu.cr"
lib/clang/bin/c2cr: lib/clang
@cd lib/clang && shards build --release --ignore-crystal-version
shard.lock:
shards install --ignore-crystal-version
shards: shard.lock
.PHONY: shards
${LIBS}:
shards install --ignore-crystal-version
vendor-libs: vendor-wgpu
.PHONY: vendor-libs
ifeq (${OS},Darwin)
# TODO: Add checks for ARM mac OS artifacts
WGPU_ARTIFACTS += bin/libs/libwgpu_native.dylib
endif
ifeq (${OS},Linux)
WGPU_ARTIFACTS += bin/libs/libwgpu_native.so
endif
# TODO: Add OS checks for Windows artifacts
vendor-wgpu: ${WGPU_ARTIFACTS}
.PHONY: vendor-wgpu
# TODO: Execute with --release for release builds
${WGPU_ARTIFACTS}: vendor/wgpu.cr native.lock.yml
crystal vendor/wgpu.cr
# macOS troubleshooting:
# https://stackoverflow.com/a/17704255/1363247
# https://developer.apple.com/forums/thread/656303
# https://www.oreilly.com/library/view/modding-mac-os/0596007094/ch04s05.html
example-headless: vendor-libs shard.lock
crystal build examples/headless.cr -o examples/headless
ifeq (${OS},Darwin)
@echo "Fixing up libwgpu_native dylib path…"
@install_name_tool -change /Users/runner/work/wgpu-native/wgpu-native/target/debug/deps/libwgpu_native.dylib @executable_path/../../Frameworks/libwgpu_native.dylib examples/headless
@otool -L examples/headless | grep wgpu
@rm -rf "examples/headless.app"
@scripts/appify.sh examples/headless
@mkdir -p "headless.app/Frameworks"
@cp bin/libs/libwgpu_native.dylib "headless.app/Frameworks"
@cp examples/Info.plist "headless.app/Contents"
@mv -f "headless.app" examples
@./examples/headless.app/Contents/MacOS/headless
else
env LD_LIBRARY_PATH=${CWD}/bin/libs examples/headless
endif
.PHONY: example-headless
example-triangle: vendor-libs shard.lock
crystal build examples/triangle.cr -o examples/triangle
ifeq (${OS},Darwin)
@echo "Fixing up libwgpu_native dylib path…"
@install_name_tool -change /Users/runner/work/wgpu-native/wgpu-native/target/debug/deps/libwgpu_native.dylib @executable_path/../../Frameworks/libwgpu_native.dylib examples/triangle
@otool -L examples/triangle | grep wgpu
@rm -rf "examples/triangle.app"
@scripts/appify.sh examples/triangle
@mkdir -p "triangle.app/Frameworks"
@cp bin/libs/libwgpu_native.dylib "triangle.app/Frameworks"
@cp examples/Info.plist "triangle.app/Contents"
@mv -f "triangle.app" examples
@./examples/triangle.app/Contents/MacOS/triangle
else
env LD_LIBRARY_PATH=${CWD}/bin/libs examples/triangle
endif
.PHONY: example-triangle