Skip to content

Commit

Permalink
Squashed 'cargokit/' changes from 62bb5c9..7a5bba8
Browse files Browse the repository at this point in the history
7a5bba8 fix: setup flutter environment for Xcode iOS builds (cunarist#30)
7467b9a fix: build_pod.sh should setup flutter environment (cunarist#29)
0f0359e fix: install targets for correct toolchain (cunarist#26)

git-subtree-dir: cargokit
git-subtree-split: 7a5bba8
  • Loading branch information
bookshiyi committed Sep 22, 2023
1 parent 7bfccda commit d665536
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 19 deletions.
14 changes: 13 additions & 1 deletion build_pod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,22 @@ 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

FLUTTER_EXPORT_BUILD_ENVIRONMENT=(
"$PODS_ROOT/../Flutter/ephemeral/flutter_export_environment.sh" # macOS
"$PODS_ROOT/../Flutter/flutter_export_environment.sh" # iOS
)

for path in "${FLUTTER_EXPORT_BUILD_ENVIRONMENT[@]}"
do
if [[ -f "$path" ]]; then
source "$path"
fi
done

"$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
# attribute on custom build phase)
ln -Fs "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" "${BUILT_PRODUCTS_DIR}/cargokit_phony"
ln -Fs "$OBJROOT/XCBuildData/build.db" "${BUILT_PRODUCTS_DIR}/cargokit_phony"
ln -Fs "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" "${BUILT_PRODUCTS_DIR}/cargokit_phony_out"
6 changes: 3 additions & 3 deletions build_tool/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ class RustBuilder {
Rustup rustup,
) {
final toolchain = _toolchain;
if (!rustup.installedToolchains.any((i) => i.startsWith('$toolchain-'))) {
if (rustup.installedTargets(toolchain) == null) {
rustup.installToolchain(toolchain);
}
if (toolchain == 'nightly') {
rustup.installRustSrcForNightly();
}
if (!rustup.installedTargets.contains(target.rust)) {
rustup.installTarget(target.rust);
if (!rustup.installedTargets(toolchain)!.contains(target.rust)) {
rustup.installTarget(target.rust, toolchain: toolchain);
}
}

Expand Down
79 changes: 64 additions & 15 deletions build_tool/lib/src/rustup.dart
Original file line number Diff line number Diff line change
@@ -1,41 +1,90 @@
import 'dart:io';

import 'package:collection/collection.dart';
import 'package:path/path.dart' as path;

import 'util.dart';

class Rustup {
final List<String> installedTargets;
final List<String> installedToolchains;
class _Toolchain {
_Toolchain(
this.name,
this.targets,
);

Rustup()
: installedTargets = _getInstalledTargets(),
installedToolchains = _getInstalledToolchains();
final String name;
final List<String> targets;
}

void installTarget(String target) {
log.info("Installing Rust target: $target");
runCommand("rustup", ['target', 'add', target]);
installedTargets.add(target);
class Rustup {
List<String>? installedTargets(String toolchain) {
final targets = _installedTargets(toolchain);
return targets != null ? List.unmodifiable(targets) : null;
}

void installToolchain(String toolchain) {
log.info("Installing Rust toolchain: $toolchain");
runCommand("rustup", ['toolchain', 'install', toolchain]);
installedToolchains.add(toolchain);
_installedToolchains
.add(_Toolchain(toolchain, _getInstalledTargets(toolchain)));
}

static List<String> _getInstalledToolchains() {
void installTarget(
String target, {
required String toolchain,
}) {
log.info("Installing Rust target: $target");
runCommand("rustup", [
'target',
'add',
'--toolchain',
toolchain,
target,
]);
_installedTargets(toolchain)?.add(target);
}

final List<_Toolchain> _installedToolchains;

Rustup() : _installedToolchains = _getInstalledToolchains();

List<String>? _installedTargets(String toolchain) => _installedToolchains
.firstWhereOrNull(
(e) => e.name == toolchain || e.name.startsWith('$toolchain-'))
?.targets;

static List<_Toolchain> _getInstalledToolchains() {
String extractToolchainName(String line) {
// ignore (default) after toolchain name
final parts = line.split(' ');
return parts[0];
}

final res = runCommand("rustup", ['toolchain', 'list']);
final lines = res.stdout
.toString()
.split('\n')
.where((e) => e.isNotEmpty)
.map(extractToolchainName)
.toList(growable: true);

return lines
.map(
(name) => _Toolchain(
name,
_getInstalledTargets(name),
),
)
.toList(growable: true);
return lines;
}

static List<String> _getInstalledTargets() {
final res = runCommand("rustup", ['target', 'list', '--installed']);
static List<String> _getInstalledTargets(String toolchain) {
final res = runCommand("rustup", [
'target',
'list',
'--toolchain',
toolchain,
'--installed',
]);
final lines = res.stdout
.toString()
.split('\n')
Expand Down

0 comments on commit d665536

Please sign in to comment.