feat: add config and refactor script to generate apple libs

This commit is contained in:
Malo Léon 2023-11-30 14:35:30 +01:00
parent edf7ae6dec
commit a85f2ae97a
7 changed files with 183 additions and 48 deletions

View File

@ -4,7 +4,7 @@
<PackageTags>Dali</PackageTags>
<Copyright>Copyright 2018 (c) INSA Rennes. All Right reserved.</Copyright>
<Author>Éric Anquetil</Author>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.1.167</Version>
<AssemblyVersion>1.1.167</AssemblyVersion>

View File

@ -123,9 +123,9 @@ namespace DALI.ToolKit.IO
public event EventHandler DeleteRequested;
//ICommand extract;
//public ICommand Extract
//{
// ICommand extract;
// public ICommand Extract
// {
// get
// {
// if (extract == null)
@ -146,6 +146,6 @@ namespace DALI.ToolKit.IO
// });
// return extract;
// }
//}
// }
}
}

View File

@ -25,5 +25,4 @@ public class Math
public float Add(float a, float b)
{
return a + b;
}
}
}

View File

@ -86,45 +86,62 @@ generate_project() {
run "beyondnetgen beyondnetgen.android.config.json"
}
# Function to build the Android libraries
build_android() {
generate_project
# Generic function to build a project
build_project() {
local platform="$1"
local config_file="$2"
local template_csproj="$3"
local output_dir="$4"
local library_extension="$5"
local abis=("${!6}")
# Copy android_fake_clang.* to generated project
cp android_fake_clang.* "$generated_project_dir/"
cd "$script_dir"
# Copy template config file
cp "$config_file" "beyondnetgen.$platform.config.json"
replace_project_names "beyondnetgen.$platform.config.json"
# Generate project
log "Generating $platform project"
run "beyondnetgen beyondnetgen.$platform.config.json"
# Copy template csproj
cp template.csproj "$generated_project_dir/$generated_project_name.csproj"
cp "$template_csproj" "$generated_project_dir/$generated_project_name.csproj"
replace_project_names "$generated_project_dir/$generated_project_name.csproj"
cd $generated_project_dir
cd "$generated_project_dir"
# For each .dll in external folder add it as a reference in the generated project
search_dir="$script_dir/external"
for entry in "$search_dir"/*; do
dll_name=$(basename $entry)
dll_name=$(basename "$entry")
log "Adding reference to $dll_name"
# Add reference to the generated project by editing the csproj file
# Search for the line <!-- ADD REFERENCES HERE (DO NOT DELETE THIS)-->
# and add a reference to the dll below it
sed -i '' "/<!-- ADD REFERENCES HERE (DO NOT DELETE THIS)-->/a \\
<Reference Include=\""$entry"\" />\\
<Reference Include=\"$entry\" />\\
" "$generated_project_dir/$generated_project_name.csproj"
done
declare -A abis
abis["arm64"]="arm64-v8a"
abis["x64"]="x86_64"
if [ "$platform" == "android" ]; then
cp $script_dir/android_fake_clang.* "$generated_project_dir/"
fi
# Build for each architecture
for arch in "${!abis[@]}"; do
log "Building Android library for $arch"
for arch in "${abis[@]}"; do
log "Building $platform library for $arch"
run "dotnet publish -r linux-bionic-$arch -v normal -c Release -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:RemoveSections=true -p:AllowUnsafeBlocks=true $generated_project_name.csproj"
run "dotnet publish -r $arch -v normal -c Release -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:RemoveSections=true -p:AllowUnsafeBlocks=true $generated_project_name.csproj"
# Copy the generated library to the output directory
mkdir -p $output_dir/${abis[$arch]}
cp $generated_project_dir/bin/Release/$output_project_net_spec/linux-bionic-$arch/native/$generated_project_name.so $output_dir/${abis[$arch]}/lib$input_project_name.so
mkdir -p "$output_dir/$arch"
cp $generated_project_dir/bin/Release/$output_project_net_spec/$arch/native/$generated_project_name.$library_extension $output_dir/$arch/$input_project_name.$library_extension
if [ "$platform" == "ios" ]; then
cd $output_dir/$arch
install_name_tool -id "$(pwd)/"$input_project_name.$library_extension"" $input_project_name.$library_extension
cd -
fi
done
# Copy the generated headers to the output directory
@ -132,25 +149,26 @@ build_android() {
cp "$generated_project_dir/Generated.h" "$output_dir/$input_project_name.h"
}
# Function to build the iOS libraries
# Definition of specific parameters for each platform
android_config_file="template.beyondnetgen.android.config.json"
ios_config_file="template.beyondnetgen.ios.config.json"
android_template_csproj="template.android.csproj"
ios_template_csproj="template.ios.csproj"
ios_library_extension="dylib"
android_library_extension="so"
# Definition of architectures for each platform
android_abis=("linux-bionic-arm64" "linux-bionic-x64")
ios_abis=( "osx-x64" "osx-arm64" "ios-arm64" "iossimulator-arm64" "iossimulator-x64")
# Calling the generic function to build the Android project
build_android() {
build_project "android" "$android_config_file" "$android_template_csproj" "$output_dir" "$android_library_extension" android_abis[@]
}
# Calling the generic function to build the iOS project
build_ios() {
cd $script_dir
# Copy template beyondnetgen.ios.config.json
cp template.beyondnetgen.ios.config.json beyondnetgen.ios.config.json
replace_project_names beyondnetgen.ios.config.json
# Generate project
log "Generating iOS project"
run "beyondnetgen beyondnetgen.ios.config.json"
# Copy $input_project_dir/bin/Release/net8.0/*.xcframework to output directory
log "Copying iOS libraries to output directory"
cp $input_project_dir/bin/Release/$output_project_net_spec/*.xcframework $output_dir
# Copy the generated headers to the output directory
log "Copying header to output directory"
cp "$generated_project_dir/Generated.h" "$output_dir/$input_project_name.h"
build_project "ios" "$ios_config_file" "$ios_template_csproj" "$output_dir" "$ios_library_extension" ios_abis[@]
}
generate_flutter() {
@ -175,7 +193,7 @@ generate_flutter() {
log "Copying generated files to flutter project"
mkdir -p $flutter_project_name/android/app/src/main/jniLibs
cp $generated_project_dir/Generated.h $flutter_project_name/Generated.h
cp -r libs/* $flutter_project_name/android/app/src/main/jniLibs/
cp -r libs/linux* $flutter_project_name/android/app/src/main/jniLibs/
cp ffigen.yaml $flutter_project_name/ffigen.yaml
cd $flutter_project_name

View File

@ -1,8 +1,5 @@
{
"AssemblyPath": "INPUT_PROJECT_NAME/bin/Release/INPUT_NET_SPEC/INPUT_PROJECT_NAME.dll",
"CSharpUnmanagedOutputPath": "GENERATED_PROJECT_NAME/Generated.cs",
"COutputPath": "GENERATED_PROJECT_NAME/Generated.h",
"Build": {
"Target": "apple-universal"
}
}
"COutputPath": "GENERATED_PROJECT_NAME/Generated.h"
}

121
template.ios.csproj Normal file
View File

@ -0,0 +1,121 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PublishTrimmed>true</PublishTrimmed>
<PublishAot>true</PublishAot>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<StripSymbols>true</StripSymbols>
<!-- TODO: Disabled for now to get faster build times -->
<Nullable>disable</Nullable>
<!-- Seems to not be required as long as we're providing the RuntimeIdentifier when calling dotnet publish/build -->
<!-- <RuntimeIdentifiers>osx-x64;osx-arm64;linux-x64;ios-arm64;iossimulator-arm64;iossimulator-x64</RuntimeIdentifiers> -->
<MixInSwift>true</MixInSwift>
</PropertyGroup>
<PropertyGroup>
<MacOSMinVersion>13.0</MacOSMinVersion>
<iOSMinVersion>16.0</iOSMinVersion>
</PropertyGroup>
<!-- Compiler Customization -->
<!-- Merge exported Symbols List -->
<Target Name="MergeExportedSymbolsList"
BeforeTargets="LinkNative"
Condition="$(MixInSwift) And ($(RuntimeIdentifier.Contains('osx')) Or $(RuntimeIdentifier.Contains('ios')))">
</Target>
<!-- Set min macOS version -->
<Choose>
<When Condition="$(RuntimeIdentifier.Contains('osx'))">
<ItemGroup>
<LinkerArg Include="-mmacosx-version-min=$(MacOSMinVersion)" />
</ItemGroup>
</When>
</Choose>
<!-- Culture stuff for iOS Support -->
<Choose>
<When Condition="$(RuntimeIdentifier.Contains('ios'))">
<!-- If globalization is not required, you can enable this instead of providing an icudt.dat file on iOS -->
<!-- <PropertyGroup>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup> -->
<!-- When this is set, an icudt.dat must be placed in the resulting bundle -->
<ItemGroup>
<RuntimeHostConfigurationOption Include="ICU_DAT_FILE_PATH" Value="icudt.dat" />
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(RuntimeIdentifier.Contains('ios'))">
<ItemGroup>
<!-- Link to Swift on iOS (it's automatic when targeting macOS) -->
<LinkerArg Include="-L/usr/lib/swift" />
</ItemGroup>
</When>
</Choose>
<!-- TODO: Temporary workarounds for iOS/iOS Simulator support -->
<Choose>
<When Condition="$(RuntimeIdentifier.Contains('ios'))">
<PropertyGroup>
<PublishAotUsingRuntimePack>true</PublishAotUsingRuntimePack>
<_IsAppleMobileLibraryMode>false</_IsAppleMobileLibraryMode>
</PropertyGroup>
</When>
</Choose>
<Choose>
<When Condition="$(RuntimeIdentifier.Contains('iossimulator'))">
<ItemGroup>
<!-- TODO: Temporary workaround for iOS Simulator support -->
<LinkerArg Include="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.0.sdk" />
<!-- Set min iOS version -->
<LinkerArg Include="-mios-simulator-version-min=$(iOSMinVersion)" />
</ItemGroup>
</When>
</Choose>
<!-- TODO: Temporary workarounds for iOS support -->
<Choose>
<When Condition="$(RuntimeIdentifier.Contains('ios-'))">
<ItemGroup>
<!-- TODO: Temporary workaround for iOS support -->
<LinkerArg Include="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk" />
<!-- Set min iOS version -->
<LinkerArg Include="-mios-version-min=$(iOSMinVersion)" />
</ItemGroup>
</When>
</Choose>
<!-- Item Excludes -->
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);.gitignore;*.sln.DotSettings;</DefaultItemExcludes>
</PropertyGroup>
<!-- Target Assembly Reference -->
<ItemGroup>
<ProjectReference Include="..\INPUT_PROJECT_NAME\INPUT_PROJECT_NAME.csproj" />
<!-- ADD REFERENCES HERE (DO NOT DELETE THIS)-->
</ItemGroup>
<!-- Assembly References -->
<ItemGroup>
</ItemGroup>
</Project>