From c6d46d47ce6384f2b0edf92d35c36dd496bdbc5c Mon Sep 17 00:00:00 2001 From: Anton Onikiychuk Date: Wed, 10 Jan 2024 15:05:06 +0200 Subject: [PATCH 1/8] fix: add `/D` argument for cd to trigger drive change when changing directory (#53) When gradle plugin runs [run_build_tool.cmd](https://github.com/irondash/cargokit/blob/a3b7352f9ebea0108d144c26437138f2903d6b35/run_build_tool.cmd) it passes to script env variable `%CARGOKIT_TOOL_TEMP_DIR%`. Then script make `cd` to dir that passed inside this variable. But if this variable points to directory that located on different drive than working directory for script, cd will not work. For it to work we need to pass `/D` parameter to `cd`. I made this change localy and it helps. Right now line [11](https://github.com/irondash/cargokit/blob/a3b7352f9ebea0108d144c26437138f2903d6b35/run_build_tool.cmd#L11) in local my script looks like: ``` cd /D "%CARGOKIT_TOOL_TEMP_DIR%" ``` and it works. This is PR that fix this issue. PS: [my inital issue](https://github.com/superlistapp/super_native_extensions/issues/290) --- run_build_tool.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_build_tool.cmd b/run_build_tool.cmd index 822e70384..d8bd094e0 100644 --- a/run_build_tool.cmd +++ b/run_build_tool.cmd @@ -8,7 +8,7 @@ SET BASEDIR=%~dp0 if not exist "%CARGOKIT_TOOL_TEMP_DIR%" ( mkdir "%CARGOKIT_TOOL_TEMP_DIR%" ) -cd "%CARGOKIT_TOOL_TEMP_DIR%" +cd /D "%CARGOKIT_TOOL_TEMP_DIR%" SET BUILD_TOOL_PKG_DIR=%BASEDIR%build_tool SET DART=%FLUTTER_ROOT%\bin\cache\dart-sdk\bin\dart From b0635958a2124bc904c2d9d5a4aa90fe3a13368b Mon Sep 17 00:00:00 2001 From: pixelshot91 Date: Wed, 10 Jan 2024 14:05:33 +0100 Subject: [PATCH 2/8] fix: build mode when using a flutter flavor (#51) plugin.gradle: Use variant.buildType.name instead of variant.name. The latter is equal to flavor + buildMode while the former is just buildMode It fixes this issue https://github.com/fzyzcjy/flutter_rust_bridge/issues/1606 --- gradle/plugin.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/plugin.gradle b/gradle/plugin.gradle index a40cf56aa..a9a6ec7a5 100644 --- a/gradle/plugin.gradle +++ b/gradle/plugin.gradle @@ -141,7 +141,7 @@ class CargoKitPlugin implements Plugin { } def task = project.tasks.create(taskName, CargoKitBuildTask.class) { - buildMode = variant.name + buildMode = variant.buildType.name buildDir = cargoBuildDir outputDir = cargoOutputDir ndkVersion = plugin.project.android.ndkVersion From f75677242424e19e5fcc6184278571280ac02fa0 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Thu, 11 Jan 2024 15:37:06 +0100 Subject: [PATCH 3/8] feat: print current dir when running pub get (#54) --- run_build_tool.cmd | 1 + 1 file changed, 1 insertion(+) diff --git a/run_build_tool.cmd b/run_build_tool.cmd index d8bd094e0..c45d0aa8b 100644 --- a/run_build_tool.cmd +++ b/run_build_tool.cmd @@ -76,6 +76,7 @@ If %ERRORLEVEL% neq 0 ( REM There is no CUR_PACKAGE_INFO it was renamed in previous step to %PREV_PACKAGE_INFO% REM which means we need to do pub get and precompile if not exist "%PRECOMPILED%" ( + echo Running pub get in "%cd%" "%DART%" pub get --no-precompile "%DART%" compile kernel bin/build_tool_runner.dart ) From a5e2126be2a3a01d2389309fbf1fa52406e0f4a5 Mon Sep 17 00:00:00 2001 From: hatch01 <42416805+hatch01@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:45:34 +0100 Subject: [PATCH 4/8] fix: building under nixos (#58) Very simple fix to build under NixOS. On NixOS, /bin/bash is not here, so the build failed. So it is much stronger to use /usr/bin/env bash. --- run_build_tool.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_build_tool.sh b/run_build_tool.sh index 0e2c97353..765d2dc18 100755 --- a/run_build_tool.sh +++ b/run_build_tool.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e From dd10277924095fcce578ed69fd1f3c5e7c4b252d Mon Sep 17 00:00:00 2001 From: Micah Thomas Date: Thu, 8 Feb 2024 08:19:25 -0700 Subject: [PATCH 5/8] fix: use alias for shasum if sha1sum is found instead (#60) Some Linux distributions might have `sha1sum` in the path but `shasum` might be missing. This will create an alias for `shasum` to fallback to `sha1sum` if available. Should close #57 --- run_build_tool.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/run_build_tool.sh b/run_build_tool.sh index 765d2dc18..6e594a23d 100755 --- a/run_build_tool.sh +++ b/run_build_tool.sh @@ -42,6 +42,12 @@ void main(List args) { } EOF +# Create alias for `shasum` if it does not exist and `sha1sum` exists +if ! [ -x "$(command -v shasum)" ] && [ -x "$(command -v sha1sum)" ]; then + shopt -s expand_aliases + alias shasum="sha1sum" +fi + # Dart run will not cache any package that has a path dependency, which # is the case for our build_tool_runner. So instead we precompile the package # ourselves. From 97668e95b40a09aecd06bef8c627d38b5f699fd8 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Thu, 8 Feb 2024 16:27:46 +0100 Subject: [PATCH 6/8] chore: fix typo in code (#63) --- build_tool/lib/src/android_environment.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_tool/lib/src/android_environment.dart b/build_tool/lib/src/android_environment.dart index f22db46eb..9342964b6 100644 --- a/build_tool/lib/src/android_environment.dart +++ b/build_tool/lib/src/android_environment.dart @@ -115,7 +115,7 @@ class AndroidEnvironment { final cxxKey = 'CXX_${target.rust}'; final cxxValue = path.join(toolchainPath, 'clang++$exe'); - final cxxfFlagsKey = 'CXXFLAGS_${target.rust}'; + final cxxFlagsKey = 'CXXFLAGS_${target.rust}'; final cxxFlagsValue = targetArg; final linkerKey = @@ -152,7 +152,7 @@ class AndroidEnvironment { ccKey: ccValue, cfFlagsKey: cFlagsValue, cxxKey: cxxValue, - cxxfFlagsKey: cxxFlagsValue, + cxxFlagsKey: cxxFlagsValue, ranlibKey: ranlibValue, rustFlagsKey: rustFlagsValue, linkerKey: selfPath, From 969c49a1b15ba8c1036cb6fc8790f40702b734b1 Mon Sep 17 00:00:00 2001 From: canxin <69547456+canxin121@users.noreply.github.com> Date: Wed, 3 Apr 2024 19:52:27 +0800 Subject: [PATCH 7/8] fix insufficient sh permissions (#65) Origin issue: https://github.com/fzyzcjy/flutter_rust_bridge/issues/1840 Origin pr: https://github.com/fzyzcjy/flutter_rust_bridge/pull/1842 Simple problem description: if you create a new flutter_rust project in windows, the sh script is automatically created, but the executable permissions cannot be set. When moving this project to macOS and executing `flutter build ios` to build ipa files the process crashes due to insufficient sh script permissions. This permission problem can be circumvented by `sh script.sh` rather than `script.sh` As verified by Github Action's macOS Runner, the modified cargokit works fine for building ipa apps using the flutter_rust project created on windows. [Action Link](https://github.com/canxin121/new_app_test/actions/runs/8466294309) --- build_pod.sh | 2 +- cmake/cargokit.cmake | 4 +++- gradle/plugin.gradle | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/build_pod.sh b/build_pod.sh index 379b9c6d2..ed0e0d987 100755 --- a/build_pod.sh +++ b/build_pod.sh @@ -49,7 +49,7 @@ do fi done -"$BASEDIR/run_build_tool.sh" build-pod "$@" +sh "$BASEDIR/run_build_tool.sh" build-pod "$@" # Make a symlink from built framework to phony file, which will be used as input to # build script. This should force rebuild (podspec currently doesn't support alwaysOutOfDate diff --git a/cmake/cargokit.cmake b/cmake/cargokit.cmake index 88326005e..ddd05df9b 100644 --- a/cmake/cargokit.cmake +++ b/cmake/cargokit.cmake @@ -50,6 +50,7 @@ function(apply_cargokit target manifest_dir lib_name any_symbol_name) else() set(SCRIPT_EXTENSION ".sh") set(IMPORT_LIB_EXTENSION "") + execute_process(COMMAND chmod +x "${cargokit_cmake_root}/run_build_tool${SCRIPT_EXTENSION}") endif() # Using generators in custom command is only supported in CMake 3.20+ @@ -75,6 +76,7 @@ function(apply_cargokit target manifest_dir lib_name any_symbol_name) ) endif() + set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/_phony_" PROPERTIES SYMBOLIC TRUE) if (TARGET ${target}) @@ -94,4 +96,4 @@ function(apply_cargokit target manifest_dir lib_name any_symbol_name) # Allow adding the output library to plugin bundled libraries set("${target}_cargokit_lib" ${OUTPUT_LIB} PARENT_SCOPE) -endfunction() \ No newline at end of file +endfunction() diff --git a/gradle/plugin.gradle b/gradle/plugin.gradle index a9a6ec7a5..12c49f110 100644 --- a/gradle/plugin.gradle +++ b/gradle/plugin.gradle @@ -55,7 +55,13 @@ abstract class CargoKitBuildTask extends DefaultTask { def manifestDir = Paths.get(project.buildscript.sourceFile.parent, project.cargokit.manifestDir) def rootProjectDir = project.rootProject.projectDir - + + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + project.exec { + commandLine 'chmod', '+x', path + } + } + project.exec { executable path args "build-gradle" From d56f1f269efeb7a7b2919dc7d8302ef6bddf47f0 Mon Sep 17 00:00:00 2001 From: Ji Fang Date: Tue, 11 Jun 2024 16:11:25 +0800 Subject: [PATCH 8/8] chore: support build as a flutter module (#70) When build as a flutter module and integrated into the existing android project, there is no applicationVariants and result in following compilation failure: Could not get unknown property 'applicationVariants' for extension 'android' of type com.android.build.gradle.LibraryExtension. In such case, we will use libraryVariants instead https://github.com/superlistapp/super_native_extensions/issues/379 --------- Co-authored-by: Ji Fang --- .github/workflows/test_example_plugin_build.yml | 6 +++++- gradle/plugin.gradle | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_example_plugin_build.yml b/.github/workflows/test_example_plugin_build.yml index bf36e8628..4fb0252dc 100644 --- a/.github/workflows/test_example_plugin_build.yml +++ b/.github/workflows/test_example_plugin_build.yml @@ -77,6 +77,10 @@ jobs: shell: bash working-directory: ${{ env.EXAMPLE_DIR }} run: | - export JAVA_HOME=$JAVA_HOME_11_X64 + if [[ $(sysctl hw.optional.arm64) == *"hw.optional.arm64: 1"* ]]; then + export JAVA_HOME=$JAVA_HOME_17_arm64 + else + export JAVA_HOME=$JAVA_HOME_11_X64 + fi flutter build apk --${{ matrix.build_mode }} -v diff --git a/gradle/plugin.gradle b/gradle/plugin.gradle index 12c49f110..37dd086af 100644 --- a/gradle/plugin.gradle +++ b/gradle/plugin.gradle @@ -116,8 +116,12 @@ class CargoKitPlugin implements Plugin { } def cargoBuildDir = "${project.buildDir}/build" + + // Determine if the project is an application or library + def isApplication = plugin.project.plugins.hasPlugin('com.android.application') + def variants = isApplication ? plugin.project.android.applicationVariants : plugin.project.android.libraryVariants - plugin.project.android.applicationVariants.all { variant -> + variants.all { variant -> final buildType = variant.buildType.name