-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathMakefile
More file actions
102 lines (88 loc) · 4.55 KB
/
Copy pathMakefile
File metadata and controls
102 lines (88 loc) · 4.55 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
QUIP_PROTOCOL_ROOT ?= /Users/romanuseinov/projects/quip/quip-protocol
QUIP_PROTOCOL_VENV := $(QUIP_PROTOCOL_ROOT)/.venv
QUIP_PROTOCOL_PYTHON := $(QUIP_PROTOCOL_VENV)/bin/python
WASM_SIGNER_CRATE := crates/transaction-crypto-wasm
WASM_SIGNER_PKG := js/quip-transaction-crypto-wasm
WASM_SIGNER_STAGE := target/wasm-signer-pkg
WASM_SIGNER_NAME := quip_transaction_crypto_wasm
WASM_PACK ?= wasm-pack
WASM_PACK_VERSION := 0.12.1
PY_SIGNER_CRATE := crates/transaction-crypto-py
PY_SIGNER_VENV := target/py-signer-venv
PY_SIGNER_PY := $(PY_SIGNER_VENV)/bin/python
PY_SIGNER_WHEELS := target/wheels
# PyO3 builds abi3 against the limited API; allow building on a CPython newer
# than the pinned pyo3 knows about (e.g. 3.14) via the forward-compat escape.
PY_SIGNER_ENV := PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
polkadot-sdk:
git clone --branch polkadot-stable2603 git@github.com:QuipNetwork/polkadot-sdk.git
local-3-node:
./scripts/start-local3.sh
quantum-validation-venv:
python3 -m venv $(QUIP_PROTOCOL_VENV)
$(QUIP_PROTOCOL_PYTHON) -m pip install -e $(QUIP_PROTOCOL_ROOT)
quantum-validation-fixtures:
QUIP_PROTOCOL_ROOT=$(QUIP_PROTOCOL_ROOT) $(QUIP_PROTOCOL_PYTHON) ./scripts/generate_quantum_validation_fixtures.py
# Build the browser signer WASM (requires `wasm-pack`). Outputs are generated
# and git-ignored; this regenerates them in place. Staged under target/ first so
# the curated package.json in the package dir is preserved.
wasm-signer:
@test "$$($(WASM_PACK) --version)" = "wasm-pack $(WASM_PACK_VERSION)" || { \
echo "wasm-pack $(WASM_PACK_VERSION) is required" >&2; exit 1; \
}
$(WASM_PACK) build $(WASM_SIGNER_CRATE) --target web --release \
--out-dir $(abspath $(WASM_SIGNER_STAGE)) --out-name $(WASM_SIGNER_NAME)
cp $(WASM_SIGNER_STAGE)/$(WASM_SIGNER_NAME).js \
$(WASM_SIGNER_STAGE)/$(WASM_SIGNER_NAME).d.ts \
$(WASM_SIGNER_STAGE)/$(WASM_SIGNER_NAME)_bg.wasm \
$(WASM_SIGNER_STAGE)/$(WASM_SIGNER_NAME)_bg.wasm.d.ts \
$(WASM_SIGNER_PKG)/
@echo "Built $(WASM_SIGNER_PKG)/$(WASM_SIGNER_NAME)_bg.wasm ($$(wc -c < $(WASM_SIGNER_PKG)/$(WASM_SIGNER_NAME)_bg.wasm) bytes)"
# Tooling venv for the Python signer (maturin + pytest). Created on demand.
$(PY_SIGNER_PY):
python3 -m venv $(PY_SIGNER_VENV)
$(PY_SIGNER_PY) -m pip install --quiet --upgrade pip 'maturin>=1.7,<2' pytest
# Build the release wheel for the Python signer and report the extension size.
# The wheel lands in target/wheels/; downstreams `pip install` it (see
# crates/transaction-crypto-py/README.md). Like wasm-signer, the compiled artifact is small
# because the crate links only the sp-free transaction-crypto-core.
py-signer: $(PY_SIGNER_PY)
$(PY_SIGNER_ENV) $(PY_SIGNER_VENV)/bin/maturin build --release \
-m $(PY_SIGNER_CRATE)/Cargo.toml --out $(PY_SIGNER_WHEELS)
@$(PY_SIGNER_PY) -c "import glob, zipfile; \
w = sorted(glob.glob('$(PY_SIGNER_WHEELS)/quip_signer-*.whl'))[-1]; \
z = zipfile.ZipFile(w); \
ext = max((i for i in z.infolist() if i.filename.endswith(('.so', '.pyd', '.dylib'))), key=lambda i: i.file_size); \
print(f'Built {ext.filename} ({ext.file_size} bytes) in {w}')"
# Build + install the extension into the venv AND drop the loose extension into
# crates/transaction-crypto-py/python/quip_signer/ (the submodule/PYTHONPATH
# staging location).
py-signer-develop: $(PY_SIGNER_PY)
$(PY_SIGNER_ENV) VIRTUAL_ENV=$(abspath $(PY_SIGNER_VENV)) \
$(PY_SIGNER_VENV)/bin/maturin develop --release \
-m $(PY_SIGNER_CRATE)/Cargo.toml
# Build the extension and run the Python test suite (parity + API).
py-signer-test: py-signer-develop
$(PY_SIGNER_PY) -m pytest $(PY_SIGNER_CRATE)/tests -q
# Build the CI images locally, for checking a Dockerfile change before pushing
# the branch. Neither target publishes: CI owns that, via the ci-images stage
# in .gitlab-ci.yml, which pushes to the project registry on any pipeline where
# a CI Dockerfile changed. Both build for the host architecture only, since the
# point is a fast local check; CI builds each arch on a native runner. The
# context is .gitlab/ rather than the repo root because nothing in either
# Dockerfile COPYs, and the root would upload target/ and venv/ for no reason.
BUILDER_IMAGE ?= quip-ci-toolchain:local
builder-image:
docker build \
--file .gitlab/ci-toolchain.Dockerfile \
--tag $(BUILDER_IMAGE) \
.gitlab/
PYPI_PUBLISH_IMAGE ?= quip-ci-pypi-publish:local
pypi-publish-image:
docker build \
--file .gitlab/ci-pypi-publish.Dockerfile \
--tag $(PYPI_PUBLISH_IMAGE) \
.gitlab/
.PHONY: local-3-node quantum-validation-venv \
quantum-validation-fixtures wasm-signer py-signer py-signer-develop \
py-signer-test builder-image pypi-publish-image