Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Apple Silicon Support #2

Merged
merged 1 commit into from
Oct 30, 2020
Merged

Conversation

sdmaclea
Copy link
Contributor

@sdmaclea sdmaclea commented Oct 23, 2020

Refactor cb.cs to build mac for x86_64 and arm64
Move arch specific build into an subdirectory

Build fat universal binaries from the arch specific libraries
Locate arch specific libraries above arch details

Depends on XCode 12.2 or greater

Details of unversal binaries can be investigated using the
lipo -detailed_info <file> command, See man lipo

Refactor cb.cs to build mac for x86_64 and arm64
Move arch specific build into an <arch> subdirectory

Build fat universal binaries from the arch specific libraries
Locate arch specific libraries above arch details

Depends on XCode 12.2 or greater

Details of unversal binaries can be investigated using the
`lipo -detailed_info <file` command, See `man lipo`
@sdmaclea
Copy link
Contributor Author

@ericsink

The diff is best viewed with ignore whitespace.

I built the e_sqlite3 dynamic and static binaries. I briefly tried the cipher libraries, but I am missing some dependencies or I don't know your workflow.... I suspect it will work for you.

Here is how I built/tested

stmaclea-mac:bld stmaclea$ xcode-select -p
/Applications/Xcode_12_beta_6.app/Contents/Developer

stmaclea-mac:bld stmaclea$ cd ..

stmaclea-mac:cb stmaclea$ cd bld

stmaclea-mac:bld stmaclea$ dotnet run

stmaclea-mac:bld stmaclea$ chmod u+x *.sh

stmaclea-mac:bld stmaclea$ ./mac_dynamic_e_sqlite3.sh 
+ mkdir -p ./bin/e_sqlite3/mac/x86_64
+ xcrun --sdk macosx clang -dynamiclib -O -arch x86_64 -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_OS_UNIX -o ./bin/e_sqlite3/mac/x86_64/libe_sqlite3.dylib ../sqlite3/sqlite3.c ../stubs/stubs.c -lc
+ mkdir -p ./bin/e_sqlite3/mac/arm64
+ xcrun --sdk macosx clang -dynamiclib -O -arch arm64 -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_OS_UNIX -o ./bin/e_sqlite3/mac/arm64/libe_sqlite3.dylib ../sqlite3/sqlite3.c ../stubs/stubs.c -lc
+ lipo ./bin/e_sqlite3/mac/x86_64/libe_sqlite3.dylib ./bin/e_sqlite3/mac/arm64/libe_sqlite3.dylib -create -output ./bin/e_sqlite3/mac/libe_sqlite3.dylib

stmaclea-mac:bld stmaclea$ ./mac_static_e_sqlite3.sh 
+ mkdir -p ./obj/e_sqlite3/mac/x86_64
+ xcrun --sdk macosx clang -O -arch x86_64 -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_OS_UNIX -c -o ./obj/e_sqlite3/mac/x86_64/sqlite3.o ../sqlite3/sqlite3.c
+ xcrun --sdk macosx clang -O -arch x86_64 -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_OS_UNIX -c -o ./obj/e_sqlite3/mac/x86_64/stubs.o ../stubs/stubs.c
+ libtool -static -o ./bin/e_sqlite3/mac/x86_64/e_sqlite3.a -filelist mac_e_sqlite3_x86_64.libtoolfiles
+ mkdir -p ./obj/e_sqlite3/mac/arm64
+ xcrun --sdk macosx clang -O -arch arm64 -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_OS_UNIX -c -o ./obj/e_sqlite3/mac/arm64/sqlite3.o ../sqlite3/sqlite3.c
+ xcrun --sdk macosx clang -O -arch arm64 -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_OS_UNIX -c -o ./obj/e_sqlite3/mac/arm64/stubs.o ../stubs/stubs.c
+ libtool -static -o ./bin/e_sqlite3/mac/arm64/e_sqlite3.a -filelist mac_e_sqlite3_arm64.libtoolfiles
+ lipo ./bin/e_sqlite3/mac/x86_64/e_sqlite3.a ./bin/e_sqlite3/mac/arm64/e_sqlite3.a -create -output ./bin/e_sqlite3/mac/e_sqlite3.a

stmaclea-mac:bld stmaclea$ lipo -detailed_info ./bin/e_sqlite3/mac/*.*
Fat header in: ./bin/e_sqlite3/mac/e_sqlite3.a
fat_magic 0xcafebabe
nfat_arch 2
architecture x86_64
    cputype CPU_TYPE_X86_64
    cpusubtype CPU_SUBTYPE_X86_64_ALL
    capabilities 0x0
    offset 48
    size 1923464
    align 2^3 (8)
architecture arm64
    cputype CPU_TYPE_ARM64
    cpusubtype CPU_SUBTYPE_ARM64_ALL
    capabilities 0x0
    offset 1923512
    size 2166496
    align 2^3 (8)
Fat header in: ./bin/e_sqlite3/mac/libe_sqlite3.dylib
fat_magic 0xcafebabe
nfat_arch 2
architecture x86_64
    cputype CPU_TYPE_X86_64
    cpusubtype CPU_SUBTYPE_X86_64_ALL
    capabilities 0x0
    offset 16384
    size 1582328
    align 2^14 (16384)
architecture arm64
    cputype CPU_TYPE_ARM64
    cpusubtype CPU_SUBTYPE_ARM64_ALL
    capabilities 0x0
    offset 1605632
    size 1511583
    align 2^14 (16384)

I have done no execution testing, but osx-arm64 testing will be enabled in ASP.NET Core before .NET 6 ships 11/2021. It is currently limited by commercial availability of Apple Silicon hardware (to populate test infrastructure).

@ericsink
Copy link
Owner

Nice. Thanks.

@ericsink ericsink merged commit 009a5ae into ericsink:master Oct 30, 2020
@sdmaclea sdmaclea deleted the AppleSilicon branch October 30, 2020 18:01
@ericsink
Copy link
Owner

I have installed XCode 12.2 and run the build scripts, for both e_sqlite3 and e_sqlcipher, and the Mac/arm64 stuff seems to build with no problems. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants