Skip to content

Commit 8e57c86

Browse files
authored
Merge pull request #5791 from moluopro/develop
Fix Apple platform detection and iOS cross-build
2 parents 08a67c8 + 6419432 commit 8e57c86

6 files changed

Lines changed: 30 additions & 25 deletions

File tree

.github/workflows/apple_m.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,12 @@ jobs:
244244
245245
- name: Crossbuild to iOS
246246
run: |
247-
#brew install llvm
248-
#export #PATH=/opt/homebrew/opt/llvm/bin:$PATH
249-
# export #LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
250-
export #CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
251-
export CC=/Applications/Xcode_26.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
252-
export CFLAGS="-O2 -unwindlib=none -Wno-macro-redefined -isysroot /Applications/Xcode_26.0.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS26.0.sdk -arch arm64 -miphoneos-version-min=10.0"
253-
xcrun --sdk iphoneos --show-sdk-path
254-
ls -l /Applications
255-
make TARGET=ARMV8 NUM_THREADS=32 HOSTCC=clang NOFORTRAN=1 CROSS=1
247+
CC="$(xcrun --sdk iphoneos --find clang)"
248+
SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)"
249+
echo "CC=${CC}"
250+
echo "SDKROOT=${SDKROOT}"
251+
make TARGET=ARMV8 DYNAMIC_ARCH=1 NUM_THREADS=32 HOSTCC=clang NOFORTRAN=1 \
252+
CC="${CC}" CFLAGS="-O2 -Wno-macro-redefined -isysroot ${SDKROOT} -arch arm64 -miphoneos-version-min=10.0"
256253
257254
xbuild-ios32:
258255
if: "github.repository == 'OpenMathLib/OpenBLAS'"
@@ -296,4 +293,3 @@ jobs:
296293
export AR=/opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar
297294
export RANLIB=/opt/homebrew/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ranlib
298295
make TARGET=ARMV7 ARM_SOFTFP_ABI=1 NUM_THREADS=32 HOSTCC=clang NOFORTRAN=1
299-

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
TOPDIR = .
22
include ./Makefile.system
33
LNCMD = ln -fs
4+
OSNAME_DISPLAY ?= $(OSNAME)
45
ifeq ($(FIXED_LIBNAME), 1)
56
LNCMD = true
67
endif
@@ -58,7 +59,7 @@ all :: tests
5859
@echo
5960
@echo " OpenBLAS build complete. ($(LIB_COMPONENTS))"
6061
@echo
61-
@echo " OS ... $(OSNAME) "
62+
@echo " OS ... $(OSNAME_DISPLAY) "
6263
@echo " Architecture ... $(ARCH) "
6364
ifndef BINARY64
6465
@echo " BINARY ... 32bit "

c_check

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ config="$2"
2323
compiler_name="$3"
2424
shift 3
2525
flags="$*"
26-
is_ios=false
26+
darwin_os=""
2727

2828
# First, we need to know the target OS and compiler name
2929
{
@@ -70,7 +70,7 @@ case "$data" in *OS_FREEBSD*) os=FreeBSD ;; esac
7070
case "$data" in *OS_NETBSD*) os=NetBSD ;; esac
7171
case "$data" in *OS_OPENBSD*) os=OpenBSD ;; esac
7272
case "$data" in *OS_DRAGONFLY*) os=DragonFly ;; esac
73-
case "$data" in *OS_DARWIN*) os=Darwin ;; esac
73+
case "$data" in *OS_DARWIN*) os=Darwin; darwin_os=macOS ;; esac
7474
case "$data" in *OS_SUNOS*) os=SunOS ;; esac
7575
case "$data" in *OS_AIX*) os=AIX ;; esac
7676
case "$data" in *OS_OSF*) os=osf ;; esac
@@ -79,7 +79,7 @@ case "$data" in *OS_CYGWIN_NT*) os=CYGWIN_NT ;; esac
7979
case "$data" in *OS_INTERIX*) os=Interix ;; esac
8080
case "$data" in *OS_ANDROID*) os=Android ;; esac
8181
case "$data" in *OS_HAIKU*) os=Haiku ;; esac
82-
case "$data" in *OS_IOS*) is_ios=true ;; esac
82+
case "$data" in *OS_IOS*) darwin_os=iOS ;; esac
8383

8484
case "$data" in
8585
*ARCH_X86_64*) architecture=x86_64 ;;
@@ -404,7 +404,7 @@ fi
404404
data=`$compiler_name $flags -S ctest1.c && grep globl ctest1.s | head -n 1 && rm -f ctest1.s`
405405

406406
need_fu=''
407-
if echo "$data" | grep 'globl[[:space:]][_\.]'; then
407+
if echo "$data" | grep -q 'globl[[:space:]][_\.]'; then
408408
need_fu="${data##*globl[[:space:]]}"
409409
need_fu="${need_fu%%[!_\.]*}"
410410
fi
@@ -421,7 +421,7 @@ fi
421421
[ "$os" = "Android" ] && [ "$hostos" = "Linux" ] && [ -n "$TERMUX_APP_PID" ] \
422422
&& cross=0
423423

424-
[ "$is_ios" = true ] && cross=1
424+
[ "$darwin_os" = iOS ] && cross=1
425425

426426
[ "$USE_OPENMP" != 1 ] && openmp=''
427427

@@ -489,11 +489,11 @@ done
489489
:> "$makefile" || exit 1
490490
:> "$config" || exit 1
491491

492-
493492
# print $data, "\n";
494493

495494
{
496495
printf "OSNAME=%s\n" "$os"
496+
[ -n "$darwin_os" ] && printf "OSNAME_DISPLAY=%s\n" "$darwin_os"
497497
printf "ARCH=%s\n" "$architecture"
498498
printf "C_COMPILER=%s\n" "$compiler"
499499
[ $binformat != 'bin32' ] && printf "BINARY32=\n"

c_check.pl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
}
5757

5858
$compiler = "";
59+
$darwin_os = "";
5960
$compiler = LSB if ($data =~ /COMPILER_LSB/);
6061
$compiler = CLANG if ($data =~ /COMPILER_CLANG/);
6162
$compiler = PGI if ($data =~ /COMPILER_PGI/);
@@ -73,7 +74,13 @@
7374
$os = NetBSD if ($data =~ /OS_NETBSD/);
7475
$os = OpenBSD if ($data =~ /OS_OPENBSD/);
7576
$os = DragonFly if ($data =~ /OS_DRAGONFLY/);
76-
$os = Darwin if ($data =~ /OS_DARWIN/);
77+
if ($data =~ /OS_DARWIN/) {
78+
$os = Darwin;
79+
$darwin_os = "macOS";
80+
}
81+
if ($data =~ /OS_IOS/) {
82+
$darwin_os = "iOS";
83+
}
7784
$os = SunOS if ($data =~ /OS_SUNOS/);
7885
$os = AIX if ($data =~ /OS_AIX/);
7986
$os = osf if ($data =~ /OS_OSF/);
@@ -391,6 +398,7 @@
391398

392399
$cross = 1 if ($os ne $hostos);
393400
$cross = 0 if (($os eq "Android") && ($hostos eq "Linux") && ($ENV{TERMUX_APP_PID} != ""));
401+
$cross = 1 if $darwin_os eq "iOS";
394402

395403
$openmp = "" if $ENV{USE_OPENMP} != 1;
396404

@@ -454,6 +462,7 @@
454462
# print $data, "\n";
455463

456464
print MAKEFILE "OSNAME=$os\n";
465+
print MAKEFILE "OSNAME_DISPLAY=$darwin_os\n" if $darwin_os ne "";
457466
print MAKEFILE "ARCH=$architecture\n";
458467
print MAKEFILE "C_COMPILER=$compiler\n";
459468
print MAKEFILE "BINARY32=\n" if $binformat ne bin32;

ctest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,6 @@ ARCH_WASM
182182
OS_WINDOWS
183183
#endif
184184

185-
#if defined(TARGET_OS_IPHONE)
185+
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
186186
OS_IOS
187187
#endif

docs/install.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,20 +710,19 @@ message about a missing declaration or missing header file complex.h)
710710
711711
### iPhone/iOS
712712
713-
As none of the current developers uses iOS, the following instructions are what
713+
As few of the current developers use iOS, the following instructions are what
714714
was found to work in our Azure CI setup, but as far as we know this builds a
715715
fully working OpenBLAS for this platform.
716716
717717
Go to the directory where you unpacked OpenBLAS,and enter the following commands:
718718
```bash
719-
CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
720-
719+
CC="$(xcrun --sdk iphoneos --find clang)"
721720
SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)"
722-
CFLAGS="-O2 -Wno-macro-redefined -isysroot $SDKROOT -arch arm64 -miphoneos-version-min=10.0"
723721
724-
make TARGET=ARMV8 DYNAMIC_ARCH=1 NUM_THREADS=32 HOSTCC=clang NOFORTRAN=1
722+
make TARGET=ARMV8 DYNAMIC_ARCH=1 NUM_THREADS=32 HOSTCC=clang NOFORTRAN=1 \
723+
CC="${CC}" CFLAGS="-O2 -Wno-macro-redefined -isysroot ${SDKROOT} -arch arm64 -miphoneos-version-min=10.0"
725724
```
726-
Adjust `MIN_IOS_VERSION` as necessary for your installation. E.g., change the version number
725+
Adjust `-miphoneos-version-min` as necessary for your installation. E.g., change the version number
727726
to the minimum iOS version you want to target and execute this file to build the library.
728727
729728
### HarmonyOS

0 commit comments

Comments
 (0)