Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
103 lines (82 loc) · 3.7 KB
/
Copy pathMakefile
File metadata and controls
103 lines (82 loc) · 3.7 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
SWIFT_MODE ?=
DEBUG ?= 1
# Load WASM SDK configuration (SDK IDs, URLs, and checksums)
include .swan-config
SWIFT_SDK ?= $(if $(filter embedded,$(SWIFT_MODE)),$(WASM_SDK_EMBEDDED),$(WASM_SDK))
BUILD_CONFIG := $(if $(filter 0 false,$(DEBUG)),release,debug)
.PHONY: help
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*##' $(firstword $(MAKEFILE_LIST)) | \
awk 'BEGIN {FS = ":.*## "}; {printf " \033[36m%-25s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Environment variables:"
@echo " SWIFT_MODE embedded (use embedded SDK) Default: (none)"
@echo " SWIFT_SDK Override selected SDK Default: $(SWIFT_SDK)"
@echo " DEBUG 1 or true = debug, 0 or false = release Default: 1"
@echo ""
@echo "Derived SDK: $(SWIFT_SDK)"
@echo ""
@echo "WASM SDK URLs and checksums are pinned in .swan-config."
@echo ""
@echo "Examples:"
@echo " make build # native debug build"
@echo " make build DEBUG=0 # native release build"
@echo " make wasm-build # WASM build"
@echo " make wasm-build SWIFT_MODE=embedded # embedded WASM build"
@echo " make wasm-all DEBUG=0 # clean + release WASM build"
@echo " make wasm-all SWIFT_MODE=embedded DEBUG=0 # clean + release embedded build"
.PHONY: debug
debug: ## Echo all Make variables
@echo "CI: $(CI)"
@echo "DEBUG: $(DEBUG)"
@echo "BUILD_CONFIG: $(BUILD_CONFIG)"
@echo "SWIFT_MODE: $(SWIFT_MODE)"
@echo "SWIFT_SDK: $(SWIFT_SDK)"
.PHONY: swift-setup
swift-setup: ## Install and activate Swift toolchain
swiftly install && swiftly use
.PHONY: sdk-install
sdk-install: ## Download and install the standard WASM SDK
node Scripts/sdk-install.mjs "$(WASM_SDK)" "$(WASM_SDK_URL)" "$(WASM_SDK_CHECKSUM)"
.PHONY: sdk-install-embedded
sdk-install-embedded: ## Download and install the embedded WASM SDK
node Scripts/sdk-install.mjs "$(WASM_SDK_EMBEDDED)" "$(WASM_SDK_URL)" "$(WASM_SDK_CHECKSUM)"
.PHONY: build
build: ## Native Swift build (DEBUG)
swift build -c $(BUILD_CONFIG)
.PHONY: test
test: ## Run Swift tests
swift test
.PHONY: clean
clean: ## Clean build artifacts
swift package clean
.PHONY: resolve
resolve: ## Resolve Swift package dependencies
swift package resolve
.PHONY: format
format: ## Format Swift source code
swift format --in-place --recursive Sources Tests Demos
.PHONY: generate-apinotes
generate-apinotes: ## Generate Dawn API notes
swift package --allow-writing-to-package-directory generate-dawn-apinotes
.PHONY: run-gameoflife
run-gameoflife: ## Run GameOfLife demo
swift run GameOfLife
.PHONY: run-bitonic
run-bitonic: ## Run BitonicSort demo
swift run BitonicSort
.PHONY: wasm-build-bridgejs
wasm-build-bridgejs: ## Generate BridgeJS bindings (SWIFT_MODE)
BUILD_WASM=1 swift package plugin --allow-writing-to-package-directory bridge-js --target WebGPUWasm
BUILD_WASM=1 swift package plugin --allow-writing-to-package-directory bridge-js --target BitonicSort
.PHONY: wasm-build
wasm-build: wasm-build-bridgejs ## WASM build, depends on bridgejs (SWIFT_MODE, DEBUG)
BUILD_WASM=1 swift build --swift-sdk $(SWIFT_SDK) --target WebGPU -c $(BUILD_CONFIG)
.PHONY: wasm-all
wasm-all: clean wasm-build ## Clean + full WASM build
.PHONY: wasm-build-bitonic
wasm-build-bitonic: wasm-build-bridgejs ## WASM build BitonicSort, depends on bridgejs (SWIFT_MODE, DEBUG)
BUILD_WASM=1 swift build --swift-sdk $(SWIFT_SDK) --target BitonicSort -c $(BUILD_CONFIG)
.PHONY: wasm-run-bitonic
wasm-run-bitonic: wasm-build-bitonic ## Build and serve BitonicSort WASM demo (SWIFT_MODE)
BUILD_WASM=1 swift package --swift-sdk $(SWIFT_SDK) js --product BitonicSort -c $(BUILD_CONFIG) && pnpx serve .