11# Makefile — build libspecter.a (Rust static library) for aarch64-apple-ios
2- # and optionally compile + link a C/C++ consumer against it .
2+ # and aarch64-apple-darwin, and optionally compile + link a C/C++ consumer.
33#
44# Usage:
5- # make — build libspecter.a (release)
6- # make debug — build libspecter.a (debug)
5+ # make — build libspecter.a for both iOS and macOS (release)
6+ # make ios — build for iOS only
7+ # make macos — build for macOS only
8+ # make debug — build for both (debug)
79# make clean — remove build artefacts
810# make check — build and run a quick symbol-presence sanity check
911#
1012# Consumer targets (set CONSUMER_SRC):
1113# make consumer CONSUMER_SRC=tests/test.c
1214# make consumer CONSUMER_SRC=tests/test.cpp
13- #
14- # Override any variable on the command line, e.g.:
15- # make CARGO_TARGET=aarch64-apple-macosx14.0
1615
1716# Rust / Cargo
1817CARGO := cargo
19- CARGO_TARGET := aarch64-apple-ios
2018RUST_PROFILE := release
21- CARGO_FLAGS := --target $(CARGO_TARGET )
2219
23- ifeq ($(RUST_PROFILE ) ,release)
24- CARGO_FLAGS += --release
25- endif
20+ IOS_TARGET := aarch64-apple-ios
21+ MACOS_TARGET := aarch64-apple-darwin
22+
23+ IOS_LIB_DIR := target/$(IOS_TARGET ) /$(RUST_PROFILE )
24+ MACOS_LIB_DIR := target/$(MACOS_TARGET ) /$(RUST_PROFILE )
25+ IOS_LIB := $(IOS_LIB_DIR ) /libspecter.a
26+ MACOS_LIB := $(MACOS_LIB_DIR ) /libspecter.a
2627
27- RUST_LIB_DIR := target/$(CARGO_TARGET ) /$(RUST_PROFILE )
28- RUST_LIB := $(RUST_LIB_DIR ) /libspecter.a
28+ CARGO_FLAGS_RELEASE := --release
2929
3030# Apple SDK / toolchain
3131SDK := iphoneos
@@ -57,7 +57,7 @@ LDFLAGS := \
5757 -arch $(ARCH ) \
5858 -isysroot $(SYSROOT ) \
5959 -miphoneos-version-min=$(MIN_IOS ) \
60- -L$(RUST_LIB_DIR ) \
60+ -L$(IOS_LIB_DIR ) \
6161 -lspectre \
6262 -lc++ \
6363 -framework Foundation \
@@ -70,24 +70,32 @@ HEADER := specter.h
7070CONSUMER_SRC ?=
7171CONSUMER_OUT ?= build/consumer
7272
73- .PHONY : all debug release consumer check clean help
73+ .PHONY : all ios macos debug debug-ios debug-macos release consumer check check-ios check-macos clean help
74+
75+ all : ios macos
76+
77+ release : all
78+
79+ ios :
80+ $(CARGO ) build --target $(IOS_TARGET ) $(CARGO_FLAGS_RELEASE )
81+ @echo " Built: $( IOS_LIB) "
7482
75- all : release
83+ macos :
84+ $(CARGO ) build --target $(MACOS_TARGET ) $(CARGO_FLAGS_RELEASE )
85+ @echo " Built: $( MACOS_LIB) "
7686
77- release :
78- $(CARGO ) build $(CARGO_FLAGS )
79- @echo " Built: $( RUST_LIB) "
87+ debug : debug-ios debug-macos
8088
81- debug : RUST_PROFILE := debug
82- debug : CARGO_FLAGS := --target $(CARGO_TARGET )
83- debug : RUST_LIB_DIR := target/$(CARGO_TARGET ) /debug
84- debug : RUST_LIB := target/$(CARGO_TARGET ) /debug/libspecter.a
85- debug :
86- $(CARGO ) build --target $(CARGO_TARGET )
87- @echo " Built: target/$( CARGO_TARGET) /debug/libspecter.a"
89+ debug-ios :
90+ $(CARGO ) build --target $(IOS_TARGET )
91+ @echo " Built: target/$( IOS_TARGET) /debug/libspecter.a"
8892
89- # Compile + link a C or C++ consumer file
90- consumer : release
93+ debug-macos :
94+ $(CARGO ) build --target $(MACOS_TARGET )
95+ @echo " Built: target/$( MACOS_TARGET) /debug/libspecter.a"
96+
97+ # Compile + link a C or C++ consumer file (against iOS build)
98+ consumer : ios
9199 @if [ -z " $( CONSUMER_SRC) " ]; then \
92100 echo " Error: set CONSUMER_SRC=path/to/file.{c,cpp}" ; exit 1; \
93101 fi
@@ -102,29 +110,40 @@ consumer: release
102110 $$ COMPILER $$ CFLAGS_USED $(CONSUMER_SRC ) $(LDFLAGS ) -o $(CONSUMER_OUT )
103111 @echo " Linked: $( CONSUMER_OUT) "
104112
105- # Sanity check: verify exported symbols are present in the static lib
106- check : release
107- @echo " ── Checking exported symbols in $( RUST_LIB) ──"
108- @nm -gU $(RUST_LIB ) | grep ' T _mem_' | sort
113+ # Sanity check: verify exported symbols are present in both builds
114+ check : check-ios check-macos
115+
116+ check-ios : ios
117+ @echo " ── Checking exported symbols in $( IOS_LIB) ──"
118+ @nm -gU $(IOS_LIB ) | grep ' T _mem_' | sort
119+ @EXPECTED=$$(grep -E '^(int32_t|size_t|void ) [[:space:]]+mem_[a-z]' $(HEADER) | wc -l | tr -d ' ' ); \
120+ FOUND=$$(nm -gU $(IOS_LIB ) | grep -c ' T _mem_' ) ; \
121+ echo " Declared in header: $$ EXPECTED | Found in lib: $$ FOUND" ; \
122+ if [ " $$ FOUND" -ge " $$ EXPECTED" ]; then echo " OK (iOS)" ; else echo " MISMATCH — check ffi.rs" ; exit 1; fi
123+
124+ check-macos : macos
125+ @echo " ── Checking exported symbols in $( MACOS_LIB) ──"
126+ @nm -gU $(MACOS_LIB ) | grep ' T _mem_' | sort
109127 @EXPECTED=$$(grep -E '^(int32_t|size_t|void ) [[:space:]]+mem_[a-z]' $(HEADER) | wc -l | tr -d ' ' ); \
110- FOUND=$$(nm -gU $(RUST_LIB ) | grep -c ' T _mem_' ) ; \
128+ FOUND=$$(nm -gU $(MACOS_LIB ) | grep -c ' T _mem_' ) ; \
111129 echo " Declared in header: $$ EXPECTED | Found in lib: $$ FOUND" ; \
112- if [ " $$ FOUND" -ge " $$ EXPECTED" ]; then echo " OK" ; else echo " MISMATCH — check ffi.rs" ; exit 1; fi
130+ if [ " $$ FOUND" -ge " $$ EXPECTED" ]; then echo " OK (macOS) " ; else echo " MISMATCH — check ffi.rs" ; exit 1; fi
113131
114132clean :
115133 $(CARGO ) clean
116134 rm -rf build
117135
118136help :
119137 @echo " Targets:"
120- @echo " all / release Build libspecter.a (release)"
121- @echo " debug Build libspecter.a (debug)"
138+ @echo " all / release Build libspecter.a for iOS and macOS (release)"
139+ @echo " ios Build for aarch64-apple-ios only"
140+ @echo " macos Build for aarch64-apple-darwin only"
141+ @echo " debug Build both targets (debug)"
122142 @echo " consumer Compile + link CONSUMER_SRC against libspecter.a"
123- @echo " check Verify exported symbols match memory.h declarations "
143+ @echo " check Verify exported symbols for both targets "
124144 @echo " clean Remove all build artefacts"
125145 @echo " "
126146 @echo " Variables:"
127- @echo " CARGO_TARGET Default: aarch64-apple-ios"
128147 @echo " SDK Default: iphoneos (use iphonesimulator for Simulator)"
129148 @echo " MIN_IOS Default: 14.0"
130149 @echo " CONSUMER_SRC Path to .c/.cpp file for the 'consumer' target"
0 commit comments