Skip to content

Commit

Permalink
prebuilt -> precompiled (consistency)
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp committed Aug 30, 2023
1 parent 53b65a5 commit 78dc165
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 77 deletions.
25 changes: 13 additions & 12 deletions build_tool/lib/src/artifacts_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ArtifactProvider {
final CargokitUserOptions userOptions;

Future<Map<Target, List<Artifact>>> getArtifacts(List<Target> targets) async {
final result = await _getPrebuiltArtifacts(targets);
final result = await _getPrecompiledArtifacts(targets);

final pendingTargets = List.of(targets);
pendingTargets.removeWhere((element) => result.containsKey(element));
Expand Down Expand Up @@ -93,14 +93,14 @@ class ArtifactProvider {
return result;
}

Future<Map<Target, List<Artifact>>> _getPrebuiltArtifacts(
Future<Map<Target, List<Artifact>>> _getPrecompiledArtifacts(
List<Target> targets) async {
if (userOptions.allowPrebuiltBinaries == false) {
_log.info('Prebuilt binaries are disabled');
if (userOptions.allowPrecompiledBinaries == false) {
_log.info('Precompiled binaries are disabled');
return {};
}
if (environment.crateOptions.prebuiltBinaries == null) {
_log.fine('Prebuilt binaries not enabled for this crate');
if (environment.crateOptions.precompiledBinaries == null) {
_log.fine('Precompiled binaries not enabled for this crate');
return {};
}

Expand All @@ -111,7 +111,7 @@ class ArtifactProvider {
'Computed crate hash $crateHash in ${start.elapsedMilliseconds}ms');

final downloadedArtifactsDir =
path.join(environment.targetTempDir, 'prebuilt', crateHash);
path.join(environment.targetTempDir, 'precompiled', crateHash);
Directory(downloadedArtifactsDir).createSync(recursive: true);

final res = <Target, List<Artifact>>{};
Expand Down Expand Up @@ -149,7 +149,7 @@ class ArtifactProvider {

// Only provide complete set of artifacts.
if (artifactsForTarget.length == requiredArtifacts.length) {
_log.fine('Found prebuilt artifacts for $target');
_log.fine('Found precompiled artifacts for $target');
res[target] = artifactsForTarget;
}
}
Expand All @@ -163,14 +163,15 @@ class ArtifactProvider {
required String signatureFileName,
required String finalPath,
}) async {
final prebuiltBinaries = environment.crateOptions.prebuiltBinaries!;
final prefix = prebuiltBinaries.uriPrefix;
final precompiledBinaries = environment.crateOptions.precompiledBinaries!;
final prefix = precompiledBinaries.uriPrefix;
final url = Uri.parse('$prefix$crateHash/$fileName');
final signatureUrl = Uri.parse('$prefix$crateHash/$signatureFileName');
final signature = await get(signatureUrl);
_log.fine('Downloading signature from $signatureUrl');
if (signature.statusCode == 404) {
_log.warning('Prebuilt binaries for available for crate hash $crateHash');
_log.warning(
'Precompiled binaries for available for crate hash $crateHash');
return;
}
if (signature.statusCode != 200) {
Expand All @@ -185,7 +186,7 @@ class ArtifactProvider {
return;
}
if (verify(
prebuiltBinaries.publicKey, res.bodyBytes, signature.bodyBytes)) {
precompiledBinaries.publicKey, res.bodyBytes, signature.bodyBytes)) {
File(finalPath).writeAsBytesSync(res.bodyBytes);
} else {
_log.shout('Signature verification failed! Ignoring binary.');
Expand Down
2 changes: 1 addition & 1 deletion build_tool/lib/src/build_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class GenKeyCommand extends Command {
final name = 'gen-key';

@override
final description = 'Generate key pair for signing prebuilt binaries';
final description = 'Generate key pair for signing precompiled binaries';

@override
void run() {
Expand Down
47 changes: 24 additions & 23 deletions build_tool/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ extension on YamlMap {
nodes.map((key, value) => MapEntry(key.value, value));
}

class PrebuiltBinaries {
class PrecompiledBinaries {
final String uriPrefix;
final PublicKey publicKey;

PrebuiltBinaries({
PrecompiledBinaries({
required this.uriPrefix,
required this.publicKey,
});
Expand All @@ -129,7 +129,7 @@ class PrebuiltBinaries {
return PublicKey(bytes);
}

static PrebuiltBinaries parse(YamlNode node) {
static PrecompiledBinaries parse(YamlNode node) {
if (node case YamlMap(valueMap: Map<dynamic, YamlNode> map)) {
if (map
case {
Expand All @@ -147,14 +147,15 @@ class PrebuiltBinaries {
_ => throw SourceSpanException(
'Invalid public key value.', publicKeyNode.span),
};
return PrebuiltBinaries(
return PrecompiledBinaries(
uriPrefix: urlPrefix,
publicKey: publicKey,
);
}
}
throw SourceSpanException(
'Invalid prebuilt binaries value. Expected Map with "url_prefix" and "public_key".',
'Invalid precompiled binaries value. '
'Expected Map with "url_prefix" and "public_key".',
node.span);
}
}
Expand All @@ -163,18 +164,18 @@ class PrebuiltBinaries {
class CargokitCrateOptions {
CargokitCrateOptions({
this.cargo = const {},
this.prebuiltBinaries,
this.precompiledBinaries,
});

final Map<BuildConfiguration, CargoBuildOptions> cargo;
final PrebuiltBinaries? prebuiltBinaries;
final PrecompiledBinaries? precompiledBinaries;

static CargokitCrateOptions parse(YamlNode node) {
if (node is! YamlMap) {
throw SourceSpanException('Cargokit options must be a map', node.span);
}
final options = <BuildConfiguration, CargoBuildOptions>{};
PrebuiltBinaries? prebuiltBinaries;
PrecompiledBinaries? precompiledBinaries;

for (final entry in node.nodes.entries) {
if (entry
Expand All @@ -198,17 +199,17 @@ class CargokitCrateOptions {
'Unknown build configuration. Must be one of ${BuildConfiguration.values.map((e) => e.name)}.',
key.span);
}
} else if (entry.key case YamlScalar(value: 'prebuilt_binaries')) {
prebuiltBinaries = PrebuiltBinaries.parse(entry.value);
} else if (entry.key case YamlScalar(value: 'precompiled_binaries')) {
precompiledBinaries = PrecompiledBinaries.parse(entry.value);
} else {
throw SourceSpanException(
'Unknown cargokit option type. Must be "cargo" or "prebuilt_binaries".',
'Unknown cargokit option type. Must be "cargo" or "precompiled_binaries".',
entry.key.span);
}
}
return CargokitCrateOptions(
cargo: options,
prebuiltBinaries: prebuiltBinaries,
precompiledBinaries: precompiledBinaries,
);
}

Expand All @@ -228,35 +229,35 @@ class CargokitCrateOptions {

class CargokitUserOptions {
// When Rustup is installed always build locally unless user opts into
// using prebuilt binaries.
static bool defaultAllowPrebuiltBinaries() {
// using precompiled binaries.
static bool defaultAllowPrecompiledBinaries() {
return Rustup.executablePath() == null;
}

CargokitUserOptions({
required this.allowPrebuiltBinaries,
required this.allowPrecompiledBinaries,
required this.verboseLogging,
});

CargokitUserOptions._()
: allowPrebuiltBinaries = defaultAllowPrebuiltBinaries(),
: allowPrecompiledBinaries = defaultAllowPrecompiledBinaries(),
verboseLogging = false;

static CargokitUserOptions parse(YamlNode node) {
if (node is! YamlMap) {
throw SourceSpanException('Cargokit options must be a map', node.span);
}
bool allowPrebuiltBinaries = defaultAllowPrebuiltBinaries();
bool allowPrecompiledBinaries = defaultAllowPrecompiledBinaries();
bool verboseLogging = false;

for (final entry in node.nodes.entries) {
if (entry.key case YamlScalar(value: 'allow_prebuilt_binaries')) {
if (entry.key case YamlScalar(value: 'allow_precompiled_binaries')) {
if (entry.value case YamlScalar(value: bool value)) {
allowPrebuiltBinaries = value;
allowPrecompiledBinaries = value;
continue;
}
throw SourceSpanException(
'Invalid value for "allow_prebuilt_binaries". Must be a boolean.',
'Invalid value for "allow_precompiled_binaries". Must be a boolean.',
entry.value.span);
} else if (entry.key case YamlScalar(value: 'verbose_logging')) {
if (entry.value case YamlScalar(value: bool value)) {
Expand All @@ -268,12 +269,12 @@ class CargokitUserOptions {
entry.value.span);
} else {
throw SourceSpanException(
'Unknown cargokit option type. Must be "allow_prebuilt_binaries" or "verbose_logging".',
'Unknown cargokit option type. Must be "allow_precompiled_binaries" or "verbose_logging".',
entry.key.span);
}
}
return CargokitUserOptions(
allowPrebuiltBinaries: allowPrebuiltBinaries,
allowPrecompiledBinaries: allowPrecompiledBinaries,
verboseLogging: verboseLogging,
);
}
Expand All @@ -300,6 +301,6 @@ class CargokitUserOptions {
return CargokitUserOptions._();
}

final bool allowPrebuiltBinaries;
final bool allowPrecompiledBinaries;
final bool verboseLogging;
}
8 changes: 4 additions & 4 deletions build_tool/lib/src/precompile_binaries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PrecompileBinaries {
final hash = CrateHash.compute(manifestDir);
_log.info('Computed crate hash: $hash');

final String tagName = 'prebuilt_$hash';
final String tagName = 'precompled_$hash';

final github = GitHub(auth: Authentication.withToken(githubToken));
final repo = github.repositories;
Expand All @@ -74,7 +74,7 @@ class PrecompileBinaries {

final tempDir = this.tempDir != null
? Directory(this.tempDir!)
: Directory.systemTemp.createTempSync('prebuilt_');
: Directory.systemTemp.createTempSync('precompiled_');

tempDir.createSync(recursive: true);

Expand Down Expand Up @@ -185,11 +185,11 @@ class PrecompileBinaries {
repositorySlug,
CreateRelease.from(
tagName: tagName,
name: 'Prebuilt binaries ${hash.substring(0, 8)}',
name: 'Precompiled binaries ${hash.substring(0, 8)}',
targetCommitish: null,
isDraft: false,
isPrerelease: false,
body: 'Prebuilt binaries for crate $libName, '
body: 'Precompiled binaries for crate $libName, '
'crate hash $hash.',
));
}
Expand Down
10 changes: 5 additions & 5 deletions build_tool/lib/src/verify_binaries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class VerifyBinaries {

Future<void> run() async {
final config = CargokitCrateOptions.load(manifestDir: manifestDir);
final prebuiltBinaries = config.prebuiltBinaries;
if (prebuiltBinaries == null) {
stdout.writeln('Crate does not support prebuilt binaries.');
final precompiledBinaries = config.precompiledBinaries;
if (precompiledBinaries == null) {
stdout.writeln('Crate does not support precompiled binaries.');
} else {
final crateHash = CrateHash.compute(manifestDir);
stdout.writeln('Crate hash: $crateHash');
Expand All @@ -38,7 +38,7 @@ class VerifyBinaries {
remote: true,
);

final prefix = prebuiltBinaries.uriPrefix;
final prefix = precompiledBinaries.uriPrefix;

bool ok = true;

Expand All @@ -64,7 +64,7 @@ class VerifyBinaries {
break;
}

if (!verify(prebuiltBinaries.publicKey, asset.bodyBytes,
if (!verify(precompiledBinaries.publicKey, asset.bodyBytes,
signature.bodyBytes)) {
stdout.writeln('INVALID SIGNATURE');
ok = false;
Expand Down
18 changes: 9 additions & 9 deletions build_tool/test/options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ extra_flags:
expect(options.flags, ['-Z', 'build-std=panic_abort,std']);
});

test('parsePrebuiltBinaries', () {
test('parsePrecompiledBinaries', () {
final yaml = """
url_prefix: https://url-prefix
public_key: a4c3433798eb2c36edf2b94dbb4dd899d57496ca373a8982d8a792410b7f6445
""";
final prebuiltBinaries = PrebuiltBinaries.parse(loadYamlNode(yaml));
final precompiledBinaries = PrecompiledBinaries.parse(loadYamlNode(yaml));
final key = HEX.decode(
'a4c3433798eb2c36edf2b94dbb4dd899d57496ca373a8982d8a792410b7f6445');
expect(prebuiltBinaries.uriPrefix, 'https://url-prefix');
expect(prebuiltBinaries.publicKey.bytes, key);
expect(precompiledBinaries.uriPrefix, 'https://url-prefix');
expect(precompiledBinaries.publicKey.bytes, key);
});

test('parseCargokitOptions', () {
Expand All @@ -44,15 +44,15 @@ cargo:
release:
toolchain: beta
prebuilt_binaries:
precompiled_binaries:
url_prefix: https://url-prefix
public_key: a4c3433798eb2c36edf2b94dbb4dd899d57496ca373a8982d8a792410b7f6445
''';
final options = CargokitCrateOptions.parse(loadYamlNode(yaml));
expect(options.prebuiltBinaries?.uriPrefix, 'https://url-prefix');
expect(options.precompiledBinaries?.uriPrefix, 'https://url-prefix');
final key = HEX.decode(
'a4c3433798eb2c36edf2b94dbb4dd899d57496ca373a8982d8a792410b7f6445');
expect(options.prebuiltBinaries?.publicKey.bytes, key);
expect(options.precompiledBinaries?.publicKey.bytes, key);

final debugOptions = options.cargo[BuildConfiguration.debug]!;
expect(debugOptions.toolchain, Toolchain.nightly);
Expand All @@ -65,11 +65,11 @@ prebuilt_binaries:

test('parseCargokitUserOptions', () {
const yaml = '''
allow_prebuilt_binaries: false
allow_precompiled_binaries: false
verbose_logging: true
''';
final options = CargokitUserOptions.parse(loadYamlNode(yaml));
expect(options.allowPrebuiltBinaries, false);
expect(options.allowPrecompiledBinaries, false);
expect(options.verboseLogging, true);
});
}
20 changes: 10 additions & 10 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ cargo:
- -Z
- build-std=panic_abort,std

# If crate ships with prebuilt binaries, they can be configured here.
prebuilt_binaries:
# Uri prefix used when downloading prebuilt binaries.
url_prefix: https://github.com/superlistapp/super_native_extensions/releases/download/prebuilt_
# If crate ships with precompiled binaries, they can be configured here.
precompiled_binaries:
# Uri prefix used when downloading precompiled binaries.
url_prefix: https://github.com/superlistapp/super_native_extensions/releases/download/precompiled_

# Public key for verifying downloaded prebuilt binaries.
# Public key for verifying downloaded precompiled binaries.
public_key: 3a257ef1c7d72d84225ac4658d24812ada50a7a7a8a2138c2a91353389fdc514
```
Expand All @@ -84,16 +84,16 @@ A `cargokit_options.yaml` file can also be placed by developer using plugin to t
# Enables verbose logging of Cargokit during build
verbose_logging: true
# Opts out of using prebuilt binaries. If crate has configured
# and deployed prebuilt binaries, these will be by default used whenever Rustup
# is not installed. With `allow_prebuilt_binaries` set to false, the build will
# Opts out of using precompiled binaries. If crate has configured
# and deployed precompiled binaries, these will be by default used whenever Rustup
# is not installed. With `allow_precompiled_binaries` set to false, the build will
# instead be aborted prompting user to install Rustup.
allow_prebuilt_binaries: false
allow_precompiled_binaries: false
```
## Detecting Rustup
When the plugin doesn't come with prebuilt libraries (or user opt-out), `build_tool` will need to invoke Rustup during build to ensure that required Rust targets and toolchain are installed for current build and to build the Rust crate.
When the plugin doesn't come with precompiled libraries (or user opt-out), `build_tool` will need to invoke Rustup during build to ensure that required Rust targets and toolchain are installed for current build and to build the Rust crate.

Cargokit will attempt to detect Rustup in the default Rustup installation location (`~/.cargo/rustup`) as well as in PATH. This is done so that if user install Rustup but doesn't properly configure PATH, Cargokit will still work.

Expand Down
Loading

0 comments on commit 78dc165

Please sign in to comment.