Skip to content

Commit

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

git-subtree-dir: cargokit
git-subtree-split: 7467b9a6374e4248879305ab2b71f367b05da6a0
  • Loading branch information
julian-CStack committed Sep 21, 2023
1 parent 545a2bc commit 38aa81a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 19 deletions.
8 changes: 7 additions & 1 deletion build_pod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ 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_ENVIRONMENT="$PODS_ROOT/../Flutter/ephemeral/flutter_export_environment.sh"

if [[ -f "$FLUTTER_EXPORT_ENVIRONMENT" ]]; then
source "$FLUTTER_EXPORT_ENVIRONMENT"
fi

"$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 38aa81a

Please sign in to comment.