feat: remove useless csharp

This commit is contained in:
Hugo Pointcheval 2023-11-09 15:47:46 +01:00
parent 382b221685
commit 5f12d30493
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC
8 changed files with 63 additions and 227 deletions

View File

@ -1,7 +0,0 @@
namespace __MainDummyNamespace;
// TODO: This is a temporary workaround to allow the .NET compiler to generate an iOS native dylib
public static class __MainDummyClass
{
public static void Main() { }
}

View File

@ -1,168 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<OutputType>Library</OutputType>
<NativeLib>Shared</NativeLib>
<SelfContained>true</SelfContained>
<TrimMode>Link</TrimMode>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<LangVersion>latest</LangVersion>
<PublishTrimmed>true</PublishTrimmed>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<Nullable>disable</Nullable>
</PropertyGroup>
<PropertyGroup>
<!--This is needed in order to build successfully Android binaries-->
<IsAndroid>$(RuntimeIdentifier.ToLower().StartsWith('android'))</IsAndroid>
<IsAndroid Condition="'$(IsAndroid)'=='false'">$(RuntimeIdentifier.ToLower().StartsWith('linux-bionic'))</IsAndroid>
<IsWindowsHost>$([MSBuild]::IsOSPlatform('Windows'))</IsWindowsHost>
<IsLinuxHost>$([MSBuild]::IsOSPlatform('Linux'))</IsLinuxHost>
<IsOSXHost>$([MSBuild]::IsOSPlatform('OSX'))</IsOSXHost>
</PropertyGroup>
<PropertyGroup>
<TrimUnusedDependencies>true</TrimUnusedDependencies>
<RootAllApplicationAssemblies>false</RootAllApplicationAssemblies>
<IlcGenerateCompleteTypeMetadata>true</IlcGenerateCompleteTypeMetadata>
<IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>
<IlcTrimMetadata>true</IlcTrimMetadata>
<IlcOptimizationPreference>Speed</IlcOptimizationPreference>
<IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>
</PropertyGroup>
<!--Following blocks are exclusive for Android building-->
<PropertyGroup Condition="$(IsAndroid) == 'true'">
<!--Use ndk-sample expected library name -->
<CppCompilerAndLinker Condition="$(IsWindowsHost) == 'true'">./android_fake_clang.cmd</CppCompilerAndLinker>
<CppCompilerAndLinker Condition="$(IsLinuxHost) == 'true'">./android_fake_clang.sh</CppCompilerAndLinker>
<CppCompilerAndLinker Condition="$(IsOSXHost) == 'true'">./android_fake_clang.command</CppCompilerAndLinker>
<NdkHost Condition="$(IsWindowsHost) == 'true'">windows-x86_64</NdkHost>
<NdkHost Condition="$(IsLinuxHost) == 'true'">linux-x86_64</NdkHost>
<NdkHost Condition="$(IsOSXHost) == 'true'">darwin-x86_64</NdkHost>
<ObjCopyName Condition="'$(ObjCopyName)' == ''">$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(NdkHost)/bin/llvm-objcopy</ObjCopyName>
<SysRoot Condition="'$(SysRoot)' == ''">$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(NdkHost)/sysroot</SysRoot>
<!--Hack for removing init and fini sections into the exports file-->
<ExportsPatch>'s/global: _init; _fini;/global: /g;'</ExportsPatch>
</PropertyGroup>
<ItemGroup Condition="$(IsAndroid) == 'true'">
<!--Hack for passing a valid target argument on NDK linker invocation-->
<LinkerArg Condition="$(RuntimeIdentifier.ToLower().EndsWith('-x64'))" Include="--target=x86_64-linux-android21" />
<LinkerArg Condition="$(RuntimeIdentifier.ToLower().EndsWith('-arm64'))" Include="--target=aarch64-linux-android21" />
</ItemGroup>
<ItemGroup Condition="$(IsAndroid) == 'true' And $(UseLibCSections) == 'true'">
<!--Hack for passing a valid target argument on NDK linker invocation-->
<LinkerArg Include="-Wl,--defsym,_init=__libc_init" />
<LinkerArg Include="-Wl,--defsym,_fini=__libc_fini" />
</ItemGroup>
<Target Name="RemoveSections" Condition="$(IsAndroid) == 'true' And $(RemoveSections) == 'true'" AfterTargets="IlcCompile" BeforeTargets="LinkNative">
<!--Reads as lines the generated exports file-->
<ReadLinesFromFile File="$(ExportsFile)">
<Output TaskParameter="Lines" PropertyName="ExportsLines" />
</ReadLinesFromFile>
<!--Gets a single text from the exports lines-->
<PropertyGroup>
<ExportsText Condition="$(ExportsLines) != ''">@(ExportsLines)</ExportsText>
</PropertyGroup>
<!--The sed tool is used as invalid lines remover-->
<Exec Command="sed -i -z $(ExportsPatch) $(ExportsFile)" />
</Target>
<PropertyGroup>
<MacOSMinVersion>13.0</MacOSMinVersion>
<iOSMinVersion>16.0</iOSMinVersion>
</PropertyGroup>
<!-- 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/iPhoneSimulator.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/iPhoneOS.sdk" />
<!-- Set min iOS version -->
<LinkerArg Include="-mios-version-min=$(iOSMinVersion)" />
</ItemGroup>
</When>
</Choose>
<!-- Strip Symbols in Release Builds -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<StripSymbols>true</StripSymbols>
</PropertyGroup>
<!-- Item Excludes -->
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);.gitignore;*.sln.DotSettings;</DefaultItemExcludes>
</PropertyGroup>
<!-- Project References -->
<ItemGroup>
<ProjectReference Include="..\MyLib.Managed\MyLib.Managed.csproj" />
</ItemGroup>
</Project>

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
dotnet publish -r linux-bionic-arm64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:RemoveSections=true

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
dotnet publish -r linux-bionic-x64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:RemoveSections=true

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
dotnet publish -r ios-arm64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:OutputType=Library

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
dotnet publish -r ios-x64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:OutputType=Library

View File

@ -1,12 +0,0 @@
#!/usr/bin/env sh
set -e
OUTPUT_PRODUCT_NAME="MyLib.Managed"
DOTNET_PATH=`which dotnet`
VERBOSITY_LEVEL="normal"
echo "Building ${OUTPUT_PRODUCT_NAME}"
${DOTNET_PATH} publish -v "${VERBOSITY_LEVEL}" /p:Configuration=Release

View File

@ -24,6 +24,8 @@ help() {
echo " -g Generated project name (default: <input-project-name>.Generated)"
echo " -o Output folder name (default: libs)"
echo " --ndk Android NDK path (default: ANDROID_NDK_HOME environment variable)"
echo " --no-android Disable Android build (default: false)"
echo " --no-ios Disable iOS build (default: false)"
}
# Function to log a message to the console and log file
@ -72,11 +74,11 @@ build_android() {
run "beyondnetgen beyondnetgen.android.config.json"
# Copy android_fake_clang.* to generated project
cp android_fake_clang.* $generated_project_dir/android_fake_clang.sh
cp android_fake_clang.* "$generated_project_dir/"
# Copy template csproj
cp template.csproj $generated_project_dir/$generated_project_name.csproj
replace_project_names $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
@ -91,8 +93,13 @@ build_android() {
run "dotnet publish -r linux-bionic-$arch -v normal -c Release -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:RemoveSections=true"
# Copy the generated library to the output directory
cp $generated_project_dir/bin/Release/net8.0/linux-bionic-$arch/native/$generated_project_name.so $output_dir/${abis[$arch]}/lib$generated_project_name.so
mkdir -p $output_dir/${abis[$arch]}
cp $generated_project_dir/bin/Release/net8.0/linux-bionic-$arch/native/$generated_project_name.so $output_dir/${abis[$arch]}/lib$input_project_name.so
done
# 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"
}
# Function to build the iOS libraries
@ -110,12 +117,21 @@ build_ios() {
# 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/net8.0/*.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"
}
## ARGUMENTS
# Set default values
WANT_TO_BUILD_ANDROID=true
WANT_TO_BUILD_IOS=true
# Check for arguments
if [ $# -eq 0 ]; then
log "No arguments supplied"
help
exit 1
fi
@ -143,7 +159,14 @@ while [ "$1" != "" ]; do
shift
export ANDROID_NDK_HOME=$1
;;
--no-android)
WANT_TO_BUILD_ANDROID=false
;;
--no-ios)
WANT_TO_BUILD_IOS=false
;;
*)
log "Unknown argument: $1"
help
exit 1
;;
@ -152,7 +175,8 @@ while [ "$1" != "" ]; do
done
# Check for required arguments
if [ -z "$input_project_dir" ]; then
if [ -z "$input_project_name" ]; then
log "Input project name is required"
help
exit 1
fi
@ -194,37 +218,49 @@ command_exists beyondnetgen || {
exit 1
}
# Check if host is macos, if so, check for xcode, and set CAN_BUILD_IOS to true
if [[ "$OSTYPE" == "darwin"* ]]; then
command_exists xcodebuild || {
log "Xcode is not installed or not in PATH. Disabling iOS build."
CAN_BUILD_IOS=false
}
# Check if host is macos, if so, check for xcode, and set BUILD_IOS to true
ostype=$(uname -s)
log "Host OS: $ostype"
if [ "$ostype" == "Darwin" ]; then
if [ "$WANT_TO_BUILD_IOS" = false ]; then
log "Disabling iOS build."
BUILD_IOS=false
else
command_exists xcodebuild || {
log "Xcode is not installed or not in PATH. Disabling iOS build."
BUILD_IOS=false
}
log "Xcode detected. Enabling iOS build."
CAN_BUILD_IOS=true
log "Xcode detected. Enabling iOS build."
BUILD_IOS=true
fi
else
log "Not running on macOS. Disabling iOS build."
CAN_BUILD_IOS=false
BUILD_IOS=false
fi
# Check for ANDROID_NDK_HOME
if [ -z "$ANDROID_NDK_HOME" ]; then
log "ANDROID_NDK_HOME is not set. Disabling Android build."
CAN_BUILD_ANDROID=false
else
if [ "$ANDROID_NDK_HOME" ] && [ "$WANT_TO_BUILD_ANDROID" = true ]; then
log "ANDROID_NDK_HOME is set to $ANDROID_NDK_HOME. Enabling Android build."
CAN_BUILD_ANDROID=true
BUILD_ANDROID=true
else
BUILD_ANDROID=false
if [ -z "$ANDROID_NDK_HOME" ]; then
log "ANDROID_NDK_HOME is not set. Disabling Android build."
else
log "Disabling Android build."
fi
fi
# Check if CAN_BUILD_IOS or CAN_BUILD_ANDROID is true
if [ "$CAN_BUILD_IOS" = false ] && [ "$CAN_BUILD_ANDROID" = false ]; then
# Check if BUILD_IOS or BUILD_ANDROID is true
if [ "$BUILD_IOS" = false ] && [ "$BUILD_ANDROID" = false ]; then
log "Neither iOS nor Android build is enabled. Aborting."
exit 1
fi
## CONFIG
cd $script_dir
# Copy template beyondnetgen.*.config.json
cp template.beyondnetgen.android.config.json beyondnetgen.android.config.json
replace_project_names beyondnetgen.android.config.json
@ -241,13 +277,12 @@ fi
## BUILD
# Clean previous build
log "Cleaning previous build"
log "Cleaning previous build..."
# Ask for confirmation
ask_confirmation "Will delete: \n$generated_project_dir, \n$output_dir, \n$input_project_dir/obj and \n$input_project_dir/bin. \nContinue?"
ask_confirmation "Will delete: $generated_project_dir, $output_dir, $input_project_dir/obj $input_project_dir/bin. Continue?"
rm -r "$generated_project_dir"
rm -r "$output_dir"
rm -r $generated_project_dir
rm -r "$input_project_dir/obj"
rm -r "$input_project_dir/bin"
@ -257,12 +292,12 @@ cd $input_project_dir
run "dotnet publish -v normal -c Release"
# Build Android libraries
if [ "$CAN_BUILD_ANDROID" = true ]; then
if [ "$BUILD_ANDROID" = true ]; then
build_android
fi
# Build iOS libraries
if [ "$CAN_BUILD_IOS" = true ]; then
if [ "$BUILD_IOS" = true ]; then
build_ios
fi