feat: add config and refactor script to generate apple libs
This commit is contained in:
parent
edf7ae6dec
commit
a85f2ae97a
@ -4,7 +4,7 @@
|
|||||||
<PackageTags>Dali</PackageTags>
|
<PackageTags>Dali</PackageTags>
|
||||||
<Copyright>Copyright 2018 (c) INSA Rennes. All Right reserved.</Copyright>
|
<Copyright>Copyright 2018 (c) INSA Rennes. All Right reserved.</Copyright>
|
||||||
<Author>Éric Anquetil</Author>
|
<Author>Éric Anquetil</Author>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Version>1.1.167</Version>
|
<Version>1.1.167</Version>
|
||||||
<AssemblyVersion>1.1.167</AssemblyVersion>
|
<AssemblyVersion>1.1.167</AssemblyVersion>
|
||||||
|
@ -26,4 +26,3 @@ public class Math
|
|||||||
{
|
{
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
90
build.sh
90
build.sh
@ -86,45 +86,62 @@ generate_project() {
|
|||||||
run "beyondnetgen beyondnetgen.android.config.json"
|
run "beyondnetgen beyondnetgen.android.config.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to build the Android libraries
|
# Generic function to build a project
|
||||||
build_android() {
|
build_project() {
|
||||||
generate_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
|
cd "$script_dir"
|
||||||
cp android_fake_clang.* "$generated_project_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
|
# 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"
|
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
|
# For each .dll in external folder add it as a reference in the generated project
|
||||||
search_dir="$script_dir/external"
|
search_dir="$script_dir/external"
|
||||||
for entry in "$search_dir"/*; do
|
for entry in "$search_dir"/*; do
|
||||||
dll_name=$(basename $entry)
|
dll_name=$(basename "$entry")
|
||||||
log "Adding reference to $dll_name"
|
log "Adding reference to $dll_name"
|
||||||
# Add reference to the generated project by editing the csproj file
|
# Add reference to the generated project by editing the csproj file
|
||||||
# Search for the line <!-- ADD REFERENCES HERE (DO NOT DELETE THIS)-->
|
# Search for the line <!-- ADD REFERENCES HERE (DO NOT DELETE THIS)-->
|
||||||
# and add a reference to the dll below it
|
# and add a reference to the dll below it
|
||||||
sed -i '' "/<!-- ADD REFERENCES HERE (DO NOT DELETE THIS)-->/a \\
|
sed -i '' "/<!-- ADD REFERENCES HERE (DO NOT DELETE THIS)-->/a \\
|
||||||
<Reference Include=\""$entry"\" />\\
|
<Reference Include=\"$entry\" />\\
|
||||||
" "$generated_project_dir/$generated_project_name.csproj"
|
" "$generated_project_dir/$generated_project_name.csproj"
|
||||||
done
|
done
|
||||||
|
|
||||||
declare -A abis
|
if [ "$platform" == "android" ]; then
|
||||||
abis["arm64"]="arm64-v8a"
|
cp $script_dir/android_fake_clang.* "$generated_project_dir/"
|
||||||
abis["x64"]="x86_64"
|
fi
|
||||||
|
|
||||||
# Build for each architecture
|
# Build for each architecture
|
||||||
for arch in "${!abis[@]}"; do
|
for arch in "${abis[@]}"; do
|
||||||
log "Building Android library for $arch"
|
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
|
# Copy the generated library to the output directory
|
||||||
mkdir -p $output_dir/${abis[$arch]}
|
mkdir -p "$output_dir/$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
|
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
|
done
|
||||||
|
|
||||||
# Copy the generated headers to the output directory
|
# 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"
|
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() {
|
build_ios() {
|
||||||
cd $script_dir
|
build_project "ios" "$ios_config_file" "$ios_template_csproj" "$output_dir" "$ios_library_extension" ios_abis[@]
|
||||||
|
|
||||||
# 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"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_flutter() {
|
generate_flutter() {
|
||||||
@ -175,7 +193,7 @@ generate_flutter() {
|
|||||||
log "Copying generated files to flutter project"
|
log "Copying generated files to flutter project"
|
||||||
mkdir -p $flutter_project_name/android/app/src/main/jniLibs
|
mkdir -p $flutter_project_name/android/app/src/main/jniLibs
|
||||||
cp $generated_project_dir/Generated.h $flutter_project_name/Generated.h
|
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
|
cp ffigen.yaml $flutter_project_name/ffigen.yaml
|
||||||
|
|
||||||
cd $flutter_project_name
|
cd $flutter_project_name
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
{
|
{
|
||||||
"AssemblyPath": "INPUT_PROJECT_NAME/bin/Release/INPUT_NET_SPEC/INPUT_PROJECT_NAME.dll",
|
"AssemblyPath": "INPUT_PROJECT_NAME/bin/Release/INPUT_NET_SPEC/INPUT_PROJECT_NAME.dll",
|
||||||
"CSharpUnmanagedOutputPath": "GENERATED_PROJECT_NAME/Generated.cs",
|
"CSharpUnmanagedOutputPath": "GENERATED_PROJECT_NAME/Generated.cs",
|
||||||
"COutputPath": "GENERATED_PROJECT_NAME/Generated.h",
|
"COutputPath": "GENERATED_PROJECT_NAME/Generated.h"
|
||||||
"Build": {
|
|
||||||
"Target": "apple-universal"
|
|
||||||
}
|
|
||||||
}
|
}
|
121
template.ios.csproj
Normal file
121
template.ios.csproj
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user