Makefile
1.PHONY: all build test clean libyrs libyrs-local libyrs-cross \
2 libyrs-linux-amd64 libyrs-linux-arm64 \
3 libyrs-freebsd-amd64 libyrs-freebsd-arm64 \
4 install-rust-targets update-yffi install-rust-default \
5 integration-test
6
7# Detect platform and architecture
8UNAME_S := $(shell uname -s)
9UNAME_M := $(shell uname -m)
10
11# Map architecture names
12ifeq ($(UNAME_M),x86_64)
13 ARCH := amd64
14endif
15ifeq ($(UNAME_M),amd64)
16 ARCH := amd64
17endif
18ifeq ($(UNAME_M),aarch64)
19 ARCH := arm64
20endif
21ifeq ($(UNAME_M),arm64)
22 ARCH := arm64
23endif
24
25# Set platform name
26ifeq ($(UNAME_S),Linux)
27 PLATFORM := linux
28endif
29ifeq ($(UNAME_S),FreeBSD)
30 PLATFORM := freebsd
31endif
32
33# Export CGO_LDFLAGS to use the correct pre-built library
34export CGO_LDFLAGS := -L$(PWD)/lib/$(PLATFORM)-$(ARCH) -lyrs -ldl -lm
35
36all: build
37
38# Install Rust cross-compilation targets for FreeBSD
39install-rust-targets:
40 rustup default nightly
41
42# Build all cross-platform libraries (requires install-rust-targets for FreeBSD)
43libyrs-cross: install-rust-default libyrs-linux-amd64 libyrs-freebsd-amd64
44 @echo "All cross-platform libraries built successfully"
45
46# Individual platform builds
47libyrs-linux-amd64: install-rust-targets
48 cd y-crdt && rustup run nightly cargo rustc --release -p yffi --target x86_64-unknown-linux-gnu --crate-type staticlib
49 mkdir -p lib/linux-amd64
50 cp y-crdt/target/x86_64-unknown-linux-gnu/release/libyrs.a lib/linux-amd64/
51 cp y-crdt/tests-ffi/include/libyrs.h lib/include/
52 @echo "Built libyrs.a for linux-amd64"
53
54libyrs-freebsd-amd64: install-rust-targets
55 rustup target add x86_64-unknown-freebsd --toolchain nightly
56 cd y-crdt && rustup run nightly cargo rustc --release -p yffi --target x86_64-unknown-freebsd --crate-type staticlib
57 mkdir -p lib/freebsd-amd64
58 cp y-crdt/target/x86_64-unknown-freebsd/release/libyrs.a lib/freebsd-amd64/
59 cp y-crdt/tests-ffi/include/libyrs.h lib/include/
60 @echo "Built libyrs.a for freebsd-amd64"
61
62# Local build for current platform (overwrites prebuilt if exists)
63libyrs-local:
64 rustup default nightly
65 cd y-crdt && rustup run nightly cargo build --release -p yffi
66 mkdir -p lib/$(PLATFORM)-$(ARCH)
67 cp y-crdt/target/release/libyrs.a lib/$(PLATFORM)-$(ARCH)/
68 cp y-crdt/tests-ffi/include/libyrs.h lib/include/
69 @echo "Built libyrs.a for local platform: $(PLATFORM)-$(ARCH)"
70
71# Alias for local build
72libyrs: libyrs-local
73
74build:
75 go build ./...
76
77test:
78 go test -v ./...
79
80integration-test:
81 RUN_INTEGRATION_TESTS=1 go test -v ./...
82
83examples:
84 cd examples && CGO_LDFLAGS="$(CGO_LDFLAGS)" go build .
85
86clean:
87 cd y-crdt && cargo clean
88 rm -rf lib/*/libyrs.a
89 go clean -cache
90
91# Update y-crdt submodule to the latest tagged release
92update-yffi:
93 @echo "Updating y-crdt submodule to latest tagged release..."
94 git submodule update --init --recursive
95 cd y-crdt && \
96 git fetch --tags && \
97 LATEST_TAG=$$(git describe --tags `git rev-list --tags --max-count=1`) && \
98 echo "Latest tag: $$LATEST_TAG" && \
99 git checkout $$LATEST_TAG && \
100 echo "Submodule updated to $$LATEST_TAG" && \
101 cd .. && \
102 sed -i "s/const YFFIVersion = \"[^\"]*/const YFFIVersion = \"$$LATEST_TAG/" yjs.go && \
103 echo "Updated YFFIVersion constant in yjs.go to $$LATEST_TAG"
104 @echo "Run 'make libyrs-cross' to rebuild all libraries"