diff --git a/MyLib.Generated/MainDummy.cs b/MyLib.Generated/MainDummy.cs
deleted file mode 100644
index ebdddd0..0000000
--- a/MyLib.Generated/MainDummy.cs
+++ /dev/null
@@ -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() { }
-}
diff --git a/MyLib.Generated/MyLib.Generated.csproj b/MyLib.Generated/MyLib.Generated.csproj
deleted file mode 100644
index 7d59396..0000000
--- a/MyLib.Generated/MyLib.Generated.csproj
+++ /dev/null
@@ -1,168 +0,0 @@
-
-
-
- net8.0
- enable
- true
- true
- Library
- Shared
- true
- Link
- true
- true
- latest
- true
- true
- true
- disable
-
-
-
-
- $(RuntimeIdentifier.ToLower().StartsWith('android'))
- $(RuntimeIdentifier.ToLower().StartsWith('linux-bionic'))
- $([MSBuild]::IsOSPlatform('Windows'))
- $([MSBuild]::IsOSPlatform('Linux'))
- $([MSBuild]::IsOSPlatform('OSX'))
-
-
-
- true
- false
- true
- false
- true
- Speed
- true
-
-
-
-
-
- ./android_fake_clang.cmd
- ./android_fake_clang.sh
- ./android_fake_clang.command
- windows-x86_64
- linux-x86_64
- darwin-x86_64
- $(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(NdkHost)/bin/llvm-objcopy
- $(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(NdkHost)/sysroot
-
- 's/global: _init; _fini;/global: /g;'
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @(ExportsLines)
-
-
-
-
-
-
- 13.0
- 16.0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- <_IsAppleMobileLibraryMode>false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
-
-
- $(DefaultItemExcludes);.gitignore;*.sln.DotSettings;
-
-
-
-
-
-
-
-
diff --git a/MyLib.Generated/build-android-arm64.sh b/MyLib.Generated/build-android-arm64.sh
deleted file mode 100755
index 34f7059..0000000
--- a/MyLib.Generated/build-android-arm64.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env sh
-
-dotnet publish -r linux-bionic-arm64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:RemoveSections=true
diff --git a/MyLib.Generated/build-android-x64.sh b/MyLib.Generated/build-android-x64.sh
deleted file mode 100755
index 8250d62..0000000
--- a/MyLib.Generated/build-android-x64.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env sh
-
-dotnet publish -r linux-bionic-x64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:RemoveSections=true
diff --git a/MyLib.Generated/build-ios-arm64.sh b/MyLib.Generated/build-ios-arm64.sh
deleted file mode 100755
index 2796c05..0000000
--- a/MyLib.Generated/build-ios-arm64.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env sh
-
-dotnet publish -r ios-arm64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:OutputType=Library
diff --git a/MyLib.Generated/build-ios-x64.sh b/MyLib.Generated/build-ios-x64.sh
deleted file mode 100755
index 12b3492..0000000
--- a/MyLib.Generated/build-ios-x64.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env sh
-
-dotnet publish -r ios-x64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true -p:OutputType=Library
diff --git a/MyLib.Managed/publish.sh b/MyLib.Managed/publish.sh
deleted file mode 100755
index 3391e53..0000000
--- a/MyLib.Managed/publish.sh
+++ /dev/null
@@ -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
diff --git a/build.sh b/build.sh
index 004397c..0a09982 100755
--- a/build.sh
+++ b/build.sh
@@ -24,6 +24,8 @@ help() {
echo " -g Generated project name (default: .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