Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
59 lines (48 loc) · 1.54 KB
/
Copy pathMakefile
File metadata and controls
59 lines (48 loc) · 1.54 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
.PHONY: all build rustlib test clean run
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
ifeq ($(GOOS),darwin)
MACOSX_DEPLOYMENT_TARGET ?= 12.0
export MACOSX_DEPLOYMENT_TARGET
# Ensure cgo compilation uses the same min version as linking.
CGO_CFLAGS ?= -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET)
CGO_LDFLAGS ?= -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET)
export CGO_CFLAGS
export CGO_LDFLAGS
endif
# Map GOOS/GOARCH to a Rust target triple we build the staticlib for.
ifeq ($(GOOS),darwin)
ifeq ($(GOARCH),arm64)
RUST_TARGET ?= aarch64-apple-darwin
else
RUST_TARGET ?= x86_64-apple-darwin
endif
else ifeq ($(GOOS),linux)
ifeq ($(GOARCH),amd64)
RUST_TARGET ?= x86_64-unknown-linux-gnu
else
RUST_TARGET ?= aarch64-unknown-linux-gnu
endif
else ifeq ($(GOOS),windows)
RUST_TARGET ?= x86_64-pc-windows-gnu
else
RUST_TARGET ?= $(shell rustc -vV | awk '/host:/ {print $$2}')
endif
LIBDIR := cgo-lib/$(RUST_TARGET)
LIB := $(LIBDIR)/libcoinset.a
all: build
rustlib:
mkdir -p "$(LIBDIR)"
cargo build --release -p coinset-ffi --target "$(RUST_TARGET)"
cp "target/$(RUST_TARGET)/release/libcoinset.a" "$(LIBDIR)/"
build: rustlib
# Go's build cache does not account for changes in linked static libraries.
# Force a rebuild so updates to libcoinset.a are reflected in the binary.
CGO_ENABLED=1 go build -a -o bin/coinset ./cmd/coinset
run: rustlib
CGO_ENABLED=1 go run ./cmd/coinset
test: rustlib
cargo test -p coinset-inspect-core
CGO_ENABLED=1 go test -count=1 ./...
clean:
rm -rf bin cgo-lib