Skip to content

Commit 3d3ea91

Browse files
committed
fix: make libdivecomputer build cache architecture-aware
The build script's skip-if-built check only tested whether libdivecomputer.a existed, not which architectures it contained. A cached arm64-only library would cause linker failures when Xcode requested a universal (arm64 + x86_64) build.
1 parent a8fd11d commit 3d3ea91

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

packages/libdivecomputer_plugin/macos/build_libdc.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,31 @@ CONFIG_DIR="${SCRIPT_DIR}/config"
1010
BUILD_DIR="${SCRIPT_DIR}/build"
1111
OUTPUT_LIB="${BUILD_DIR}/libdivecomputer.a"
1212

13-
# Skip rebuild if already built
14-
if [ -f "${OUTPUT_LIB}" ]; then
15-
echo "libdivecomputer.a already built, skipping."
16-
exit 0
13+
mkdir -p "${BUILD_DIR}"
14+
15+
# Determine architectures to build for.
16+
# ARCHS is set by Xcode during the build phase.
17+
if [ -z "${ARCHS:-}" ]; then
18+
ARCHS="$(uname -m)"
1719
fi
1820

19-
mkdir -p "${BUILD_DIR}"
21+
# Skip rebuild if the library already contains all requested architectures.
22+
if [ -f "${OUTPUT_LIB}" ]; then
23+
EXISTING_ARCHS=$(xcrun lipo -archs "${OUTPUT_LIB}" 2>/dev/null || echo "")
24+
NEEDS_REBUILD=false
25+
for arch in ${ARCHS}; do
26+
if ! echo "${EXISTING_ARCHS}" | grep -qw "${arch}"; then
27+
NEEDS_REBUILD=true
28+
break
29+
fi
30+
done
31+
if [ "${NEEDS_REBUILD}" = false ]; then
32+
echo "libdivecomputer.a already contains [${EXISTING_ARCHS}], skipping."
33+
exit 0
34+
fi
35+
echo "libdivecomputer.a has [${EXISTING_ARCHS}] but need [${ARCHS}], rebuilding."
36+
rm -f "${OUTPUT_LIB}"
37+
fi
2038

2139
# All source files from Makefile.am (excluding Windows-specific files)
2240
SOURCES=(
@@ -94,12 +112,6 @@ CFLAGS=(
94112
SDKROOT=$(xcrun --show-sdk-path)
95113
CFLAGS+=(-isysroot "${SDKROOT}")
96114

97-
# Determine architectures to build for.
98-
# ARCHS is set by Xcode during the build phase.
99-
if [ -z "${ARCHS:-}" ]; then
100-
ARCHS="$(uname -m)"
101-
fi
102-
103115
echo "Building libdivecomputer for macOS (architectures: ${ARCHS})..."
104116

105117
ARCH_LIBS=()

0 commit comments

Comments
 (0)