Skip to content

Commit

Permalink
Make the XCFramework work for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldeicaza committed May 30, 2023
1 parent 62e4109 commit 6305b12
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ all:
echo - release: Builds an xcframework package, documentation and pushes documentation

build-docs:
GENERATE_DOCS=1 swift package --allow-writing-to-directory $(ODOCS) generate-documentation Documentation.docc --target SwiftGodot --disable-indexing --transform-for-static-hosting --hosting-base-path /SwiftGodotDocs --emit-digest --output-path $(ODOCS)
GENERATE_DOCS=1 swift package --allow-writing-to-directory $(ODOCS) generate-documentation Documentation.docc --target SwiftGodot --disable-indexing --transform-for-static-hosting --hosting-base-path /SwiftGodotDocs --emit-digest --output-path $(ODOCS) >& build-docs.log

push-docs:
(cd ../SwiftGodotDocs; mv docs tmp; git reset --hard 8b5f69a631f42a37176a040aeb5cfa1620249ff1; mv tmp docs; git add docs/*; git commit -m "Import Docs"; git push -f; git prune)

release: build-release build-docs push-docs
release: check-args build-release build-docs push-docs

build-release:
build-release: check-args
sh scripts/release $(VERSION) $(NOTES)

check-args:
@if test x$(VERSION)$(NOTES) = x; then echo You need to provide both VERSION=XX NOTES=FILENAME arguments to this makefile target; exit 1; fi
10 changes: 8 additions & 2 deletions Sources/SwiftGodot/EntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,14 @@ public func initializeSwiftModule (
deInitHook: @escaping (GDExtension.InitializationLevel)->())
{
gi = UnsafePointer<GDExtensionInterface> (interfacePtr).pointee
print ("initializingSwiftModule with library=\(library)")
library = GDExtensionClassLibraryPtr(libraryPtr)

// For now, we will only initialize the library once, so all of the SwiftGodot
// modules are bundled together. This is not optimal, see this bug
// with a description of what we should be doing:
// https://github.com/migueldeicaza/SwiftGodot/issues/72
if library == nil {
library = GDExtensionClassLibraryPtr(libraryPtr)
}
let initialization = UnsafeMutablePointer<GDExtensionInitialization> (extensionPtr)
initialization.pointee.deinitialize = extension_deinitialize
initialization.pointee.initialize = extension_initialize
Expand Down
7 changes: 7 additions & 0 deletions scripts/make-swiftgodot-framework
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ lipo -create -output ./universal/SwiftGodot.framework/SwiftGodot $bdMac/PackageF
xcodebuild -create-xcframework -framework ./universal/SwiftGodot.framework -framework $bdiOS/PackageFrameworks/SwiftGodot.framework -output $2
rm -rf ./universal
fd=$2//macos-arm64_x86_64/SwiftGodot.framework
ifd=$2/ios-arm64/SwiftGodot.framework
(cd $fd; mkdir -p Versions/Current/Headers; ln -sf Versions/Current/Headers .)
(cd $fd; mkdir -p Versions/Current/Modules; ln -sf Versions/Current/Modules .)
(cd $ifd; mkdir -p Versions/Current/Headers; ln -sf Versions/Current/Headers .)
(cd $ifd; mkdir -p Versions/Current/Modules; ln -sf Versions/Current/Modules .)
rsync -a $bdMac/SwiftGodot.swiftmodule $fd/Versions/Current/Modules/
rsync -a $bdMacArm/SwiftGodot.swiftmodule $fd/Versions/Current/Modules/
rsync -a $bdiOS/SwiftGodot.swiftmodule $ifd/Versions/Current/Modules/

cat > $fd/Modules/module.modulemap << EOF
framework module SwiftGodot {
Expand Down Expand Up @@ -368,3 +372,6 @@ FOUNDATION_EXPORT const unsigned char SwiftGodotVersionString[];
EOF

cp $fd/Modules/module.modulemap $ifd/Modules/module.modulemap
cp $fd/Headers/SwiftGodot-Swift.h $ifd/Headers/SwiftGodot-Swift.h
8 changes: 5 additions & 3 deletions scripts/release
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ mkdir -p $archivePath
echo Building on $dir
echo DerivedData: $derivedData
echo ArchiveData: $archivePath

xcodebuild -scheme SwiftGodot -destination platform=generic/macOS,arch=x86_64 -derivedDataPath $derivedData -archivePath $archivePath >& $dir/x86_64.log
xcodebuild -scheme SwiftGodot -destination platform=generic/macOS,arch=arm64 -derivedDataPath "${derivedData}_arm" -archivePath $archivePath >& $dir/arm64.log
start=`date`
xcodebuild -scheme SwiftGodot -destination platform=macOS,arch=x86_64 -derivedDataPath $derivedData -archivePath $archivePath >& $dir/x86_64.log
xcodebuild -scheme SwiftGodot -destination platform=macOS,arch=arm64 -derivedDataPath "${derivedData}_arm" -archivePath $archivePath >& $dir/arm64.log
xcodebuild -scheme SwiftGodot -destination generic/platform=iOS -derivedDataPath $derivedData -archivePath $archivePath >& $dir/arm64.log
sh scripts/make-swiftgodot-framework $dir/derived/ $outputDir/SwiftGodot.xcframework

Expand Down Expand Up @@ -81,3 +81,5 @@ let package = Package(
EOF

(cd ../SwiftGodotBinary; git tag $tag; git commit -m "Update to $tag" -a; git push)
echo Started at: $start
echo Ended at `date`

0 comments on commit 6305b12

Please sign in to comment.