Skip to content

Commit

Permalink
Squashed 'cargokit/' changes from 52b2251..62bb5c9
Browse files Browse the repository at this point in the history
62bb5c9 chore: test iOS flavor and nightly for release build (#20)
fa301d5 fix: [android] specify compiler extension on windows (#22)
98f6e01 feat: allow configuring verbose mode through CARGOKIT_VERBOSE env (#21)
6d421f9 chore: add CI test for building example plugin (#17)
1f644b2 feat: add workaround for pub path resolving bug (#19)
c1e8fcf fix: script argument escaping (#18)
34cc336 Merge pull request #16 from irondash/build_configuraiton_parse_ignore_flavor
be425f7 fix: parsing configuration should ignore flavor
32b6720 Merge pull request #15 from irondash/fix_pod_dylib_bundle_replacement
bfd4bcc fix: [pod] exception when building bundle dylib

git-subtree-dir: cargokit
git-subtree-split: 62bb5c9b6c9b3eca1071baf78606bc7f43632133
  • Loading branch information
julian-CStack committed Sep 12, 2023
1 parent d4e7d4a commit 545a2bc
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 14 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/test_example_plugin_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
on:
pull_request:
push:
branches:
- main

name: Test Example Plugin

jobs:
Build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
build_mode:
- debug
- profile
- release
env:
EXAMPLE_DIR: "a b/hello_rust_ffi_plugin/example"
CARGOKIT_VERBOSE: 1
steps:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Setup Repository
shell: bash
run: |
mkdir "a b" # Space is intentional
cd "a b"
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
# "advanced" branch has extra iOS flavor and uses rust nightly for release builds
git clone -b advanced https://github.com/irondash/hello_rust_ffi_plugin
cd hello_rust_ffi_plugin
git subtree pull --prefix cargokit https://github.com/irondash/cargokit.git ${{ steps.extract_branch.outputs.branch }} --squash
- uses: subosito/flutter-action@v1
with:
channel: "stable"
- name: Install GTK
if: (matrix.os == 'ubuntu-latest')
run: sudo apt-get update && sudo apt-get install libgtk-3-dev
- name: Install ninja-build
if: (matrix.os == 'ubuntu-latest')
run: sudo apt-get update && sudo apt-get install ninja-build
- name: Build Linux (${{ matrix.build_mode }})
if: matrix.os == 'ubuntu-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build linux --${{ matrix.build_mode }} -v
- name: Build macOS (${{ matrix.build_mode }})
if: matrix.os == 'macos-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build macos --${{ matrix.build_mode }} -v
- name: Build iOS (${{ matrix.build_mode }})
if: matrix.os == 'macos-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build ios --${{ matrix.build_mode }} --no-codesign -v
- name: Build iOS (${{ matrix.build_mode }}) - flavor1
if: matrix.os == 'macos-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build ios --flavor flavor1 --${{ matrix.build_mode }} --no-codesign -v
- name: Build Windows (${{ matrix.build_mode }})
if: matrix.os == 'windows-latest'
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: flutter build windows --${{ matrix.build_mode }} -v
- name: Build Android (${{ matrix.build_mode }})
shell: bash
working-directory: ${{ env.EXAMPLE_DIR }}
run: |
export JAVA_HOME=$JAVA_HOME_11_X64
flutter build apk --${{ matrix.build_mode }} -v
5 changes: 4 additions & 1 deletion build_pod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ set -e

BASEDIR=$(dirname "$0")

# Workaround for https://github.com/dart-lang/pub/issues/4010
BASEDIR=$(cd "$BASEDIR" ; pwd -P)

# Remove XCode SDK from path. Otherwise this breaks tool compilation when building iOS project
NEW_PATH=`echo $PATH | tr ":" "\n" | grep -v "Contents/Developer/" | tr "\n" ":"`

Expand Down Expand Up @@ -34,7 +37,7 @@ export CARGOKIT_TOOL_TEMP_DIR=$TARGET_TEMP_DIR/build_tool
# Directory inside root project. Not necessarily the top level directory of root project.
export CARGOKIT_ROOT_PROJECT_DIR=$SRCROOT

"$BASEDIR/run_build_tool.sh" build-pod $@
"$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
Expand Down
9 changes: 6 additions & 3 deletions build_tool/lib/src/android_environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class AndroidEnvironment {
'sdkmanager$sdkManagerExtension',
);

log.info('Installing NDK $ndkVersion');
runCommand(sdkManager, [
'--install',
'ndk;$ndkVersion',
Expand All @@ -95,6 +96,8 @@ class AndroidEnvironment {
final minSdkVersion =
math.max(target.androidMinSdkVersion!, this.minSdkVersion);

final exe = Platform.isWindows ? '.exe' : '';

final arKey = 'AR_${target.rust}';
final arValue = ['${target.rust}-ar', 'llvm-ar', 'llvm-ar.exe']
.map((e) => path.join(toolchainPath, e))
Expand All @@ -106,20 +109,20 @@ class AndroidEnvironment {
final targetArg = '--target=${target.rust}$minSdkVersion';

final ccKey = 'CC_${target.rust}';
final ccValue = path.join(toolchainPath, 'clang');
final ccValue = path.join(toolchainPath, 'clang$exe');
final cfFlagsKey = 'CFLAGS_${target.rust}';
final cFlagsValue = targetArg;

final cxxKey = 'CXX_${target.rust}';
final cxxValue = path.join(toolchainPath, 'clang++');
final cxxValue = path.join(toolchainPath, 'clang++$exe');
final cxxfFlagsKey = 'CXXFLAGS_${target.rust}';
final cxxFlagsValue = targetArg;

final linkerKey =
'cargo_target_${target.rust.replaceAll('-', '_')}_linker'.toUpperCase();

final ranlibKey = 'RANLIB_${target.rust}';
final ranlibValue = path.join(toolchainPath, 'llvm-ranlib');
final ranlibValue = path.join(toolchainPath, 'llvm-ranlib$exe');

final ndkVersionParsed = Version.parse(ndkVersion);
final rustFlagsKey = 'CARGO_ENCODED_RUSTFLAGS';
Expand Down
1 change: 1 addition & 0 deletions build_tool/lib/src/build_pod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class BuildPod {
'@rpath/$bundlePath',
targetFile,
]);
return;
}
}
throw Exception('Unable to find bundle for dynamic library');
Expand Down
3 changes: 2 additions & 1 deletion build_tool/lib/src/build_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ abstract class BuildCommand extends Command {
Future<void> run() async {
final options = CargokitUserOptions.load();

if (options.verboseLogging) {
if (options.verboseLogging ||
Platform.environment['CARGOKIT_VERBOSE'] == '1') {
enableVerboseLogging();
}

Expand Down
24 changes: 17 additions & 7 deletions build_tool/lib/src/builder.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:collection/collection.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;

import 'android_environment.dart';
Expand All @@ -9,6 +10,8 @@ import 'rustup.dart';
import 'target.dart';
import 'util.dart';

final _log = Logger('builder');

enum BuildConfiguration {
debug,
release,
Expand Down Expand Up @@ -61,17 +64,24 @@ class BuildEnvironment {
this.javaHome,
});

static BuildEnvironment fromEnvironment({
required bool isAndroid,
}) {
static BuildConfiguration parseBuildConfiguration(String value) {
// XCode configuration adds the flavor to configuration name.
final firstSegment = value.split('-').first;
final buildConfiguration = BuildConfiguration.values.firstWhereOrNull(
(e) => e.name == Environment.configuration,
(e) => e.name == firstSegment,
);
if (buildConfiguration == null) {
throw BuildException(
'Unknown build configuration: ${Environment.configuration}',
);
_log.warning('Unknown build configuraiton $value, will assume release');
return BuildConfiguration.release;
}
return buildConfiguration;
}

static BuildEnvironment fromEnvironment({
required bool isAndroid,
}) {
final buildConfiguration =
parseBuildConfiguration(Environment.configuration);
final manifestDir = Environment.manifestDir;
final crateOptions = CargokitCrateOptions.load(
manifestDir: manifestDir,
Expand Down
2 changes: 1 addition & 1 deletion build_tool/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CommandFailedException implements Exception {
final stdout = result.stdout.toString().trim();
final stderr = result.stderr.toString().trim();
return [
"External Command: $executable ${arguments.join(' ')}",
"External Command: $executable ${arguments.map((e) => '"$e"').join(' ')}",
"Returned Exit Code: ${result.exitCode}",
kSeparator,
"STDOUT:",
Expand Down
28 changes: 28 additions & 0 deletions build_tool/test/builder_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:build_tool/src/builder.dart';
import 'package:test/test.dart';

void main() {
test('parseBuildConfiguration', () {
var b = BuildEnvironment.parseBuildConfiguration('debug');
expect(b, BuildConfiguration.debug);

b = BuildEnvironment.parseBuildConfiguration('profile');
expect(b, BuildConfiguration.profile);

b = BuildEnvironment.parseBuildConfiguration('release');
expect(b, BuildConfiguration.release);

b = BuildEnvironment.parseBuildConfiguration('debug-dev');
expect(b, BuildConfiguration.debug);

b = BuildEnvironment.parseBuildConfiguration('profile');
expect(b, BuildConfiguration.profile);

b = BuildEnvironment.parseBuildConfiguration('profile-prod');
expect(b, BuildConfiguration.profile);

// fallback to release
b = BuildEnvironment.parseBuildConfiguration('unknown');
expect(b, BuildConfiguration.release);
});
}
8 changes: 8 additions & 0 deletions cmake/cargokit.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
SET(cargokit_cmake_root "${CMAKE_CURRENT_LIST_DIR}/..")

# Workaround for https://github.com/dart-lang/pub/issues/4010
get_filename_component(cargokit_cmake_root "${cargokit_cmake_root}" REALPATH)

if(WIN32)
# REALPATH does not properly resolve symlinks on windows :-/
execute_process(COMMAND powershell -File "${CMAKE_CURRENT_LIST_DIR}/resolve_symlinks.ps1" "${cargokit_cmake_root}" OUTPUT_VARIABLE cargokit_cmake_root OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

# Arguments
# - target: CMAKE target to which rust library is linked
# - manifest_dir: relative path from current folder to directory containing cargo manifest
Expand Down
27 changes: 27 additions & 0 deletions cmake/resolve_symlinks.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Resolve-Symlinks {
[CmdletBinding()]
[OutputType([string])]
param(
[Parameter(Position = 0, Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string] $Path
)

[string] $separator = '/'
[string[]] $parts = $Path.Split($separator)

[string] $realPath = ''
foreach ($part in $parts) {
if ($realPath -and !$realPath.EndsWith($separator)) {
$realPath += $separator
}
$realPath += $part
$item = Get-Item $realPath
if ($item.Target) {
$realPath = $item.Target.Replace('\', '/')
}
}
$realPath
}

$path=Resolve-Symlinks -Path $args[0]
Write-Host $path
2 changes: 1 addition & 1 deletion run_build_tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ if [ ! -f "$PACKAGE_HASH_FILE" ]; then
echo "$PACKAGE_HASH" > "$PACKAGE_HASH_FILE"
fi

"$DART" bin/build_tool_runner.dill $@
"$DART" bin/build_tool_runner.dill "$@"

0 comments on commit 545a2bc

Please sign in to comment.