-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
130 lines (112 loc) · 3.98 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
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
# We cannot use $(shell pwd), which will return unix path format on Windows,
# making it hard to use.
cur_dir = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
TOP := $(cur_dir)
# RUSTFLAGS that are likely to be tweaked by developers. For example,
# while we enable debug logs by default here, some might want to strip them
# for minimal code size / consumed cycles.
CUSTOM_RUSTFLAGS := --cfg debug_assertions
# Additional cargo args to append here. For example, one can use
# make test CARGO_ARGS="-- --nocapture" so as to inspect data emitted to
# stdout in unit tests
CARGO_ARGS :=
MODE := release
# Tweak this to change the clang version to use for building C code. By default
# we use a bash script with somes heuristics to find clang in current system.
CLANG := $(shell $(TOP)/scripts/find_clang)
# When this is set, a single contract will be built instead of all contracts
CONTRACT :=
# By default, we would clean build/{release,debug} folder first, in case old
# contracts are mixed together with new ones, if for some reason you want to
# revert this behavior, you can change this to anything other than true
CLEAN_BUILD_DIR_FIRST := true
BUILD_DIR := build/$(MODE)
# Some older crates might not be parpared to be built against clang, we would
# need to override CFLAGS to prepare them.
TARGET_CFLAGS := --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs \
-nostdinc -nostdlib \
-I $(TOP)deps/ckb-c-stdlib/libc -DCKB_DECLARATION_ONLY
# Pass setups to child make processes
export CUSTOM_RUSTFLAGS
export TOP
export CARGO_ARGS
export MODE
export CLANG
export BUILD_DIR
export TARGET_CFLAGS
default: build test
build:
@if [ "x$(CLEAN_BUILD_DIR_FIRST)" = "xtrue" ]; then \
echo "Cleaning $(BUILD_DIR) directory..."; \
rm -rf $(BUILD_DIR); \
fi
mkdir -p $(BUILD_DIR)
@set -eu; \
if [ "x$(CONTRACT)" = "x" ]; then \
for contract in $(wildcard contracts/*); do \
$(MAKE) -e -C $$contract build; \
done; \
else \
$(MAKE) -e -C contracts/$(CONTRACT) build; \
fi
# Run a single make task for a specific contract. For example:
#
# make run CONTRACT=stack-reorder TASK=adjust_stack_size STACK_SIZE=0x200000
TASK :=
run:
$(MAKE) -e -C contracts/$(CONTRACT) $(TASK)
# test, check, clippy and fmt here are provided for completeness,
# there is nothing wrong invoking cargo directly instead of make.
test:
cargo test $(CARGO_ARGS)
check:
cargo check $(CARGO_ARGS)
clippy:
cargo clippy $(CARGO_ARGS)
fmt:
cargo fmt $(CARGO_ARGS)
# Arbitrary cargo command is supported here. For example:
#
# make cargo CARGO_CMD=expand CARGO_ARGS="--ugly"
#
# Invokes:
# cargo expand --ugly
CARGO_CMD :=
cargo:
cargo $(CARGO_CMD) $(CARGO_ARGS)
clean:
rm -rf build
cargo clean
TEMPLATE_TYPE := --git
TEMPLATE_REPO := https://github.com/cryptape/ckb-script-templates
CRATE :=
TEMPLATE := contract
DESTINATION := contracts
generate:
@set -eu; \
if [ "x$(CRATE)" = "x" ]; then \
cargo generate $(TEMPLATE_TYPE) $(TEMPLATE_REPO) $(TEMPLATE) \
--destination $(DESTINATION); \
echo "Please update workspace-level Cargo.toml so members include the newly created crate!"; \
else \
cargo generate $(TEMPLATE_TYPE) $(TEMPLATE_REPO) $(TEMPLATE) \
--destination $(DESTINATION) \
--name $(CRATE); \
sed '/@@INSERTION_POINT@@/s/$$/\n "$(DESTINATION)\/$(CRATE)",/' Cargo.toml > Cargo.toml.new; \
mv Cargo.toml.new Cargo.toml; \
fi
prepare:
rustup target add riscv64imac-unknown-none-elf
# Generate checksum info for reproducible build
CHECKSUM_FILE := build/checksums-$(MODE).txt
checksum: build
sha256sum build/$(MODE)/* > $(CHECKSUM_FILE)
# Generate schemas
schemas:
moleculec --language rust --schema-file schemas/rgbpp.mol > crates/core/src/schemas/rgbpp.rs
cargo fmt
# Docker reproducible build
docker-build:
docker run --rm -v `pwd`:/code docker.io/xxuejie/rust-n-llvm@sha256:71e98a25eb0350c779cdea18c296d101c4ddc375b8fd96531b63f3105ca64ca2 bash -c "cd /code; make checksum MODE=release CHECKSUM_FILE=checksums.txt"
sha256sum -c checksums.txt
.PHONY: build test check clippy fmt cargo clean prepare checksum schemas docker-build