11#! /bin/bash
22# Test builds on macOS (run natively on macOS CI runner or local machine)
3- # Usage: ./test-macos.sh [portable|rid|aot|all]
3+ # Usage: ./test-macos.sh [portable|rid|singlefile| aot|all]
44set -e
55
66SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
@@ -23,6 +23,8 @@ echo "Detected macOS architecture: $ARCH (RID: $RID)"
2323
2424build_package () {
2525 echo " ==> Building Secp256k1.Net NuGet package..."
26+ # Clear any cached version of the local test package from global cache
27+ rm -rf ~ /.nuget/packages/secp256k1.net/0.0.1-localtest.1
2628 dotnet pack " $REPO_ROOT /Secp256k1.Net" -c Release -o " $REPO_ROOT /pkg" -p:Version=0.0.1-localtest.1
2729}
2830
@@ -110,6 +112,65 @@ test_rid_specific() {
110112 fi
111113}
112114
115+ test_singlefile () {
116+ local output_dir=" $SCRIPT_DIR /publish/singlefile-$RID "
117+
118+ echo " --- Testing single-file build for $RID ---"
119+ rm -rf " $output_dir "
120+
121+ dotnet nuget locals http-cache --clear > /dev/null 2>&1 || true
122+ rm -rf obj bin
123+ dotnet publish -c Release -r " $RID " --self-contained -p:PublishSingleFile=true -o " $output_dir "
124+
125+ # Verify only single native library is present (alongside the single-file executable)
126+ echo " Verifying single native library..."
127+
128+ if [ -d " $output_dir /runtimes" ]; then
129+ echo " FAILED: Found 'runtimes' directory in single-file publish"
130+ ls -la " $output_dir /runtimes/" 2> /dev/null || true
131+ return 1
132+ fi
133+
134+ local native_count
135+ native_count=$( find " $output_dir " -maxdepth 1 -type f -name " *.dylib" | wc -l | tr -d ' ' )
136+
137+ if [ " $native_count " -ne 1 ]; then
138+ echo " FAILED: Expected 1 native library (.dylib), found $native_count "
139+ echo " Files in publish directory:"
140+ ls -la " $output_dir "
141+ return 1
142+ fi
143+
144+ if [ ! -f " $output_dir /$NATIVE_LIB " ]; then
145+ echo " FAILED: Expected $NATIVE_LIB not found"
146+ echo " Files in publish directory:"
147+ ls -la " $output_dir "
148+ return 1
149+ fi
150+
151+ # Verify single-file executable exists
152+ if [ ! -f " $output_dir /NativeLibTest" ]; then
153+ echo " FAILED: Single-file executable not found"
154+ echo " Files in publish directory:"
155+ ls -la " $output_dir "
156+ return 1
157+ fi
158+
159+ echo " OK: Found $NATIVE_LIB and NativeLibTest executable"
160+
161+ # Run the single-file executable directly (not via dotnet)
162+ echo " Running single-file test..."
163+ if " $output_dir /NativeLibTest" ; then
164+ echo " --- Single-file $RID : PASSED ---"
165+ echo
166+ return 0
167+ else
168+ echo " --- Single-file $RID : FAILED ---"
169+ echo
170+ return 1
171+ fi
172+ }
173+
113174test_aot () {
114175 local output_dir=" $SCRIPT_DIR /publish/aot-$RID "
115176
@@ -186,17 +247,21 @@ case "$BUILD_MODE" in
186247 rid)
187248 test_rid_specific || failed=1
188249 ;;
250+ singlefile)
251+ test_singlefile || failed=1
252+ ;;
189253 aot)
190254 test_aot || failed=1
191255 ;;
192256 all)
193257 test_portable || failed=1
194258 test_rid_specific || failed=1
259+ test_singlefile || failed=1
195260 test_aot || failed=1
196261 ;;
197262 * )
198263 echo " Unknown build mode: $BUILD_MODE "
199- echo " Usage: $0 [portable|rid|aot|all]"
264+ echo " Usage: $0 [portable|rid|singlefile| aot|all]"
200265 exit 1
201266 ;;
202267esac
0 commit comments