-
Notifications
You must be signed in to change notification settings - Fork 202
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
[Swift bindings] Add bindings experimental NuGet to the dotnet-experimental feed #2878
Open
kotlarmilos
wants to merge
16
commits into
feature/swift-bindings
Choose a base branch
from
swift-bindings/experimental-bindings
base: feature/swift-bindings
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
076f3c3
Test bindings build
kotlarmilos 67e3206
Test bindings build
kotlarmilos c8b97c3
Test bindings build
kotlarmilos a38d7ef
Test bindings build
kotlarmilos d1f5ad2
Test bindings build
kotlarmilos a49ab38
Test bindings build
kotlarmilos 70002ab
Test bindings build
kotlarmilos 40781e8
Test bindings build
kotlarmilos 2260301
Test bindings build
kotlarmilos af128f2
Move HikingApp to FrameworkTests
kotlarmilos d0c47aa
Update solution
kotlarmilos 473cf0a
Add comment
kotlarmilos ae32243
Ensure generated bindings are AOT compatible
kotlarmilos 1582c46
Merge branch 'feature/swift-bindings' of github.com:dotnet/runtimelab…
kotlarmilos 0559ae6
Merge branch 'feature/swift-bindings' of github.com:dotnet/runtimelab…
kotlarmilos f6b333e
Remove unused test helper
kotlarmilos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,138 @@ | ||||||
#!/usr/bin/env bash | ||||||
|
||||||
usage() | ||||||
{ | ||||||
echo "Common settings:" | ||||||
echo " --platform <value> Platform: MacOSX, iPhoneOS, iPhoneSimulator, AppleTVOS, AppleTVSimulator" | ||||||
echo " --arch <value> Architecture: arm64e-apple-macos, x86_64-apple-macos" | ||||||
echo " --framework Framework to generate bindings for" | ||||||
echo " --help Print help and exit (short: -h)" | ||||||
echo "" | ||||||
|
||||||
echo "Actions:" | ||||||
echo " --experimental Generates only Runtime.Swift namespace when bindings for frameworks are not complete" | ||||||
} | ||||||
|
||||||
source="${BASH_SOURCE[0]}" | ||||||
|
||||||
# resolve $SOURCE until the file is no longer a symlink | ||||||
while [[ -h $source ]]; do | ||||||
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" | ||||||
source="$(readlink "$source")" | ||||||
|
||||||
# if $source was a relative symlink, we need to resolve it relative to the path where the | ||||||
# symlink file was located | ||||||
[[ $source != /* ]] && source="$scriptroot/$source" | ||||||
done | ||||||
|
||||||
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" | ||||||
|
||||||
platform='' | ||||||
arch='' | ||||||
frameworks=() | ||||||
experimental=false | ||||||
|
||||||
output_dir="./GeneratedBindings" | ||||||
|
||||||
while [[ $# > 0 ]]; do | ||||||
opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" | ||||||
case "$opt" in | ||||||
-help|-h) | ||||||
usage | ||||||
exit 0 | ||||||
;; | ||||||
-experimental) | ||||||
experimental=true | ||||||
;; | ||||||
-platform) | ||||||
platform=$2 | ||||||
shift | ||||||
;; | ||||||
-arch) | ||||||
arch=$2 | ||||||
shift | ||||||
;; | ||||||
-framework) | ||||||
frameworks+=("$2") | ||||||
shift | ||||||
;; | ||||||
esac | ||||||
|
||||||
shift | ||||||
done | ||||||
|
||||||
# Output directory for generated bindings | ||||||
rm -rf "$output_dir" | ||||||
mkdir -p "$output_dir" | ||||||
|
||||||
cd "$output_dir" | ||||||
|
||||||
# Function to extract ABI file | ||||||
function ExtractABI { | ||||||
local framework=$1 | ||||||
|
||||||
echo "Generating ABI for framework '$framework', platform '$platform', architecture '$arch'" | ||||||
|
||||||
local sdk_path=$(xcrun -sdk $(echo "$platform" | tr '[:upper:]' '[:lower:]') --show-sdk-path) | ||||||
local swift_interface_path="/Applications/Xcode.app/Contents/Developer/Platforms/${platform}.platform/Developer/SDKs/${platform}.sdk/System/Library/Frameworks/${framework}.framework/Versions/Current/Modules/${framework}.swiftmodule/${arch}.swiftinterface" | ||||||
|
||||||
if [ ! -f "$swift_interface_path" ]; then | ||||||
echo "Error: Swift interface file not found for framework '$framework'." | ||||||
return 1 | ||||||
fi | ||||||
|
||||||
xcrun swift-frontend -compile-module-from-interface "$swift_interface_path" \ | ||||||
-module-name "$framework" \ | ||||||
-sdk "$sdk_path" \ | ||||||
-emit-abi-descriptor-path "./${framework}.abi.json" | ||||||
} | ||||||
|
||||||
# Function to generate bindings | ||||||
function InvokeProjectionTooling { | ||||||
local framework=$1 | ||||||
|
||||||
$scriptroot/.dotnet/dotnet $scriptroot/artifacts/bin/Swift.Bindings/Release/net9.0/Swift.Bindings.dll -a "$framework" -o "./" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
if $experimental; then | ||||||
rm -rf "./Swift.$framework.cs" | ||||||
fi | ||||||
} | ||||||
|
||||||
# Function to generate NuGet package | ||||||
function PackNuGet { | ||||||
local project_file="./Swift.Bindings.${platform}.Experimental.csproj" | ||||||
|
||||||
cat <<EOL > "$project_file" | ||||||
<Project Sdk="Microsoft.NET.Sdk"> | ||||||
<PropertyGroup> | ||||||
<TargetFramework>net9.0</TargetFramework> | ||||||
<ImplicitUsings>enable</ImplicitUsings> | ||||||
<Nullable>enable</Nullable> | ||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||||||
<IsPackable>true</IsPackable> | ||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||||||
<IsAotCompatible>true</IsAotCompatible> | ||||||
</PropertyGroup> | ||||||
</Project> | ||||||
EOL | ||||||
|
||||||
$scriptroot/.dotnet/dotnet pack "$project_file" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
function Generate { | ||||||
for framework in "${frameworks[@]}"; do | ||||||
echo "Processing framework: $framework" | ||||||
|
||||||
if ExtractABI "$framework"; then | ||||||
InvokeProjectionTooling "$framework" | ||||||
else | ||||||
echo "Skipping framework '$framework' due to errors." | ||||||
fi | ||||||
done | ||||||
|
||||||
PackNuGet | ||||||
|
||||||
echo "Process completed." | ||||||
} | ||||||
|
||||||
Generate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions
13
src/Swift.Bindings/tests/FrameworkTests/Swift.Bindings.Framework.Tests.csproj
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use
xcode-select -p
to figure out path to Xcode rather than hardcoding /Applications