-
-
Notifications
You must be signed in to change notification settings - Fork 925
Expand file tree
/
Copy pathMakefile
More file actions
163 lines (138 loc) · 4.31 KB
/
Makefile
File metadata and controls
163 lines (138 loc) · 4.31 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#
# Prerequisites:
# - git, make, cmake, rustup, python 3.10+, node.js
# - Windows: Git Bash
# - Linux: python3-pip, python3-venv, clang, libclang-dev, libsdl2-dev 2.32.0
# - ./scripts/setup_venv
#
# Each new shell:
# - macOS/Linux: source .venv/bin/activate
# - Windows (Git Bash): source .venv/Scripts/activate
#
# Native:
# - Lint: make lint
# - Build: make clean build
# - Test: make test
# - Run: make run
#
# WASM:
# - Setup once:
# git clone --branch 0.29.3 --depth 1 https://github.com/pyodide/pyodide.git pyodide
# cd pyodide/emsdk
# CMAKE_POLICY_VERSION_MINIMUM=3.5 make
# - Each new shell before WASM commands:
# source pyodide/emsdk/emsdk_env.sh
# - Lint: make lint-wasm
# - Build: make clean-wasm build-wasm
# - Run: make run-wasm
#
# Web pages:
# - Setup once: cd web && npm install
# - Build: make pages
#
# Project directories
ROOT_DIR := .
CRATES_DIR := $(ROOT_DIR)/crates
DIST_DIR := $(ROOT_DIR)/dist
PYTHON_DIR := $(ROOT_DIR)/python
SCRIPTS_DIR := $(ROOT_DIR)/scripts
# Build targets
TARGET ?= $(shell rustc -vV | awk '/^host:/ {print $$2}')
WASM_TARGET := wasm32-unknown-emscripten
# WASM path remap flags
REMAP_SRC_PATH := $(abspath $(ROOT_DIR))
REMAP_USER_HOME ?= /user
RUST_REMAP_FLAGS := --remap-path-prefix=$(REMAP_SRC_PATH)=/src/pyxel
WASM_PREFIX_MAP_FLAGS := -ffile-prefix-map=$(REMAP_SRC_PATH)=/src/pyxel
ifneq ($(HOME),)
RUST_REMAP_FLAGS += --remap-path-prefix=$(HOME)=$(REMAP_USER_HOME)
WASM_PREFIX_MAP_FLAGS += -ffile-prefix-map=$(HOME)=$(REMAP_USER_HOME)
endif
# Build options
ifeq ($(TARGET),$(WASM_TARGET))
RUSTFLAGS += \
$(RUST_REMAP_FLAGS) \
-C panic=abort \
-C link-arg=-fwasm-exceptions \
-C link-arg=-sSIDE_MODULE=2 \
-C link-arg=-lSDL2 \
-C link-arg=-lhtml5
CFLAGS += $(WASM_PREFIX_MAP_FLAGS)
CXXFLAGS += $(WASM_PREFIX_MAP_FLAGS)
endif
CARGO_OPTS := --release --target $(TARGET) -Zbuild-std=std,panic_abort
ifneq (,$(or $(findstring windows,$(TARGET)),$(findstring darwin,$(TARGET))))
CARGO_OPTS += --features sdl2_static
else
CARGO_OPTS += --features sdl2_dynamic
endif
# Tool options
CLIPPY_OPTS := -q -- --no-deps
MATURIN_OPTS := --manylinux off
# PyO3 environment
ifneq ($(TARGET),$(WASM_TARGET))
PYTHON ?= python3
PYO3_PYTHON ?= $(shell which $(PYTHON))
PYO3_ENVIRONMENT_SIGNATURE ?= $(shell $(PYTHON) -c \
"import sys,platform; v=sys.version_info; \
a=platform.architecture()[0]; \
print(f'{sys.implementation.name}-{v.major}.{v.minor}-{a}')")
lint build test run: export PYO3_PYTHON := $(PYO3_PYTHON)
lint build test run: export PYO3_ENVIRONMENT_SIGNATURE := $(PYO3_ENVIRONMENT_SIGNATURE)
endif
.PHONY: \
all clean distclean update format lint build install test run \
clean-wasm lint-wasm build-wasm run-wasm \
pages
all: build
clean:
@cd $(CRATES_DIR); cargo clean --target $(TARGET)
distclean:
@rm -rf $(DIST_DIR)
@rm -rf $(CRATES_DIR)/target
update:
@rustup -q update
@cargo -q install cargo-outdated
@cd $(CRATES_DIR); cargo -q update
@cd $(CRATES_DIR); cargo -q outdated --root-deps-only
@pip3 install --upgrade pip
@pip3 -q install -U -r $(PYTHON_DIR)/requirements.txt
format:
@cd $(CRATES_DIR); cargo fmt -- --emit=files
@ruff format $(ROOT_DIR)
@npx prettier --write --log-level warn "$(ROOT_DIR)/**/*.{css,html,js,json}"
lint:
@cd $(CRATES_DIR); cargo clippy $(CARGO_OPTS) $(CLIPPY_OPTS)
@ruff check $(ROOT_DIR)
build:
@rustup component add rust-src
@rustup target add $(TARGET)
@$(SCRIPTS_DIR)/generate_pyi_docstrings
@$(SCRIPTS_DIR)/generate_docs
@cp LICENSE $(PYTHON_DIR)/pyxel
@cd $(PYTHON_DIR); \
RUSTFLAGS="$(RUSTFLAGS)" \
CFLAGS="$(CFLAGS)" \
CXXFLAGS="$(CXXFLAGS)" \
maturin build -o ../$(DIST_DIR) $(CARGO_OPTS) $(MATURIN_OPTS)
install: build
@pip3 install --force-reinstall "$$(ls -rt $(DIST_DIR)/*.whl | tail -n 1)"
test: install
@cd $(ROOT_DIR); python -m pytest python/tests/ -v
@cd $(CRATES_DIR); cargo test -p pyxel-core $(CARGO_OPTS)
run: install
@$(SCRIPTS_DIR)/run_examples
clean-wasm:
@$(MAKE) clean TARGET=$(WASM_TARGET)
lint-wasm:
@$(MAKE) lint TARGET=$(WASM_TARGET)
build-wasm:
@embuilder build sdl2 --pic
@rm -f $(DIST_DIR)/*-emscripten_*.whl
@$(MAKE) build TARGET=$(WASM_TARGET)
@$(SCRIPTS_DIR)/check_wasm_wheel
@$(SCRIPTS_DIR)/install_wasm_wheel
run-wasm: build-wasm
@$(SCRIPTS_DIR)/start_showcase
pages:
@cd $(ROOT_DIR)/web && npx @tailwindcss/cli -i styles/input.css -o styles.css --minify