-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow cross-compiling AOT snapshots in benchmark builder #701
Open
osa1
wants to merge
3
commits into
google:master
Choose a base branch
from
osa1:benchmark_cross_comp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−31
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,12 @@ import 'package:pool/pool.dart' show Pool; | |
Future<void> main(List<String> args) async { | ||
final argParser = ArgParser() | ||
..addOption('target', | ||
mandatory: false, defaultsTo: 'aot,exe,jit,js,js-production') | ||
..addOption('jobs', abbr: 'j', mandatory: false); | ||
mandatory: false, defaultsTo: 'exe,jit,js,js-production') | ||
..addOption('jobs', abbr: 'j', mandatory: false) | ||
..addOption('aot-target', mandatory: false, defaultsTo: 'x64'); | ||
|
||
final parsedArgs = argParser.parse(args); | ||
final env = Platform.environment; | ||
|
||
var jobs = Platform.numberOfProcessors; | ||
if (parsedArgs['jobs'] != null) { | ||
|
@@ -23,7 +25,23 @@ Future<void> main(List<String> args) async { | |
for (final targetStr in parsedArgs['target'].split(',')) { | ||
switch (targetStr) { | ||
case 'aot': | ||
targets.add(aotTarget); | ||
final dartSdkPath = env["DART_SDK"]; | ||
|
||
if (dartSdkPath == null) { | ||
print('\$DART_SDK needs to be set when generating aot snapshots'); | ||
exit(1); | ||
} | ||
|
||
final parsedAotTarget = parsedArgs['aot-target']; | ||
final aotTarget = aotTargets[parsedAotTarget]; | ||
if (aotTarget == null) { | ||
print('Unsupported aot target: $parsedAotTarget'); | ||
print( | ||
'Supported aot targets: ${aotTargets.keys.toList().join(', ')}'); | ||
exit(1); | ||
} | ||
|
||
targets.add(makeAotTarget(dartSdkPath, aotTarget)); | ||
break; | ||
|
||
case 'exe': | ||
|
@@ -60,7 +78,7 @@ Future<void> main(List<String> args) async { | |
.toList(); | ||
} | ||
|
||
final commands = <List<String>>[]; | ||
final commands = <ProcessInstructions>[]; | ||
|
||
if (sourceFiles.isNotEmpty && targets.isNotEmpty) { | ||
try { | ||
|
@@ -79,11 +97,21 @@ Future<void> main(List<String> args) async { | |
|
||
final pool = Pool(jobs); | ||
|
||
final stream = pool.forEach<List<String>, CompileProcess>(commands, | ||
(List<String> command) async { | ||
final commandStr = command.join(' '); | ||
final stream = pool.forEach<ProcessInstructions, CompileProcess>(commands, | ||
(ProcessInstructions command) async { | ||
var envStr = ''; | ||
if (command.environment != null) { | ||
envStr = command.environment!.entries | ||
.map((entry) => '${entry.key}=${entry.value}') | ||
.join(' ') + | ||
' '; | ||
} | ||
final commandStr = | ||
'$envStr${command.executable} ${command.arguments.join(' ')}'; | ||
print(commandStr); | ||
final result = await Process.run(command[0], command.sublist(1)); | ||
|
||
final result = await Process.run(command.executable, command.arguments, | ||
environment: command.environment); | ||
return CompileProcess(commandStr, result); | ||
}); | ||
|
||
|
@@ -107,6 +135,39 @@ Future<void> main(List<String> args) async { | |
await pool.done; | ||
} | ||
|
||
/// Stores [Process.run] arguments | ||
class ProcessInstructions { | ||
final String executable; | ||
final List<String> arguments; | ||
final Map<String, String>? environment; | ||
|
||
ProcessInstructions(this.executable, this.arguments, {this.environment}); | ||
} | ||
|
||
/// Supported aot snapshot targets | ||
enum AotTarget { | ||
x64, | ||
armv7hf, | ||
armv8, | ||
} | ||
|
||
/// Maps `--aot-target` arguments to their [AotTarget]s | ||
const aotTargets = <String, AotTarget>{ | ||
'x64': AotTarget.x64, | ||
'armv7hf': AotTarget.armv7hf, | ||
'armv8': AotTarget.armv8, | ||
}; | ||
|
||
/// Maps [AotTarget]s to `DART_CONFIGURATION` env values when invoking `precompiler2` | ||
// TODO: Product or release? | ||
const aotTargetDartConfiguration = <AotTarget, String>{ | ||
AotTarget.x64: "ProductX64", | ||
AotTarget.armv7hf: "ProductXARM/clang_x86", | ||
AotTarget.armv8: "ProductXARM64/clang_x64", | ||
}; | ||
|
||
/// Packs a debug string for a command being run to the command's result, to be | ||
/// able to show which command failed and why | ||
class CompileProcess { | ||
final String command; | ||
final ProcessResult result; | ||
|
@@ -116,7 +177,7 @@ class CompileProcess { | |
|
||
class Target { | ||
final String _name; | ||
final List<String> Function(String) _processArgs; | ||
final ProcessInstructions Function(String sourceFile) _processArgs; | ||
|
||
const Target(this._name, this._processArgs); | ||
|
||
|
@@ -125,63 +186,71 @@ class Target { | |
return 'Target($_name)'; | ||
} | ||
|
||
List<String> compileArgs(String sourceFile) { | ||
ProcessInstructions compileArgs(String sourceFile) { | ||
return _processArgs(sourceFile); | ||
} | ||
} | ||
|
||
Target makeAotTarget(String dartSdkPath, AotTarget aotTarget) { | ||
return Target('aot', (sourceFile) { | ||
final baseName = path.basename(sourceFile); | ||
final baseNameNoExt = path.withoutExtension(baseName); | ||
// TODO: Do we need `-Ddart.vm.product=true`? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes :) |
||
return ProcessInstructions('$dartSdkPath/pkg/vm/tool/precompiler2', [ | ||
sourceFile, | ||
'out/$baseNameNoExt.aot' | ||
], environment: { | ||
'DART_CONFIGURATION': aotTargetDartConfiguration[aotTarget]! | ||
}); | ||
}); | ||
} | ||
|
||
const aotTarget = Target('aot', aotProcessArgs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this |
||
const exeTarget = Target('exe', exeProcessArgs); | ||
const jitTarget = Target('jit', jitProcessArgs); | ||
const jsTarget = Target('js', jsProcessArgs); | ||
const jsProductionTarget = Target('js-production', jsProductionProcessArgs); | ||
|
||
List<String> aotProcessArgs(String sourceFile) { | ||
ProcessInstructions aotProcessArgs(String sourceFile) { | ||
final baseName = path.basename(sourceFile); | ||
final baseNameNoExt = path.withoutExtension(baseName); | ||
return [ | ||
'dart', | ||
'compile', | ||
'aot-snapshot', | ||
sourceFile, | ||
'-o', | ||
'out/$baseNameNoExt.aot' | ||
]; | ||
return ProcessInstructions('dart', | ||
['compile', 'aot-snapshot', sourceFile, '-o', 'out/$baseNameNoExt.aot']); | ||
} | ||
|
||
List<String> exeProcessArgs(String sourceFile) { | ||
ProcessInstructions exeProcessArgs(String sourceFile) { | ||
final baseName = path.basename(sourceFile); | ||
final baseNameNoExt = path.withoutExtension(baseName); | ||
return ['dart', 'compile', 'exe', sourceFile, '-o', 'out/$baseNameNoExt.exe']; | ||
return ProcessInstructions( | ||
'dart', ['compile', 'exe', sourceFile, '-o', 'out/$baseNameNoExt.exe']); | ||
} | ||
|
||
List<String> jitProcessArgs(String sourceFile) { | ||
ProcessInstructions jitProcessArgs(String sourceFile) { | ||
final baseName = path.basename(sourceFile); | ||
final baseNameNoExt = path.withoutExtension(baseName); | ||
return [ | ||
'dart', | ||
return ProcessInstructions('dart', [ | ||
'--snapshot-kind=kernel', | ||
'--snapshot=out/$baseNameNoExt.dill', | ||
sourceFile | ||
]; | ||
]); | ||
} | ||
|
||
List<String> jsProcessArgs(String sourceFile) { | ||
ProcessInstructions jsProcessArgs(String sourceFile) { | ||
final baseName = path.basename(sourceFile); | ||
final baseNameNoExt = path.withoutExtension(baseName); | ||
return ['dart', 'compile', 'js', sourceFile, '-o', 'out/$baseNameNoExt.js']; | ||
return ProcessInstructions( | ||
'dart', ['compile', 'js', sourceFile, '-o', 'out/$baseNameNoExt.js']); | ||
} | ||
|
||
List<String> jsProductionProcessArgs(String sourceFile) { | ||
ProcessInstructions jsProductionProcessArgs(String sourceFile) { | ||
final baseName = path.basename(sourceFile); | ||
final baseNameNoExt = path.withoutExtension(baseName); | ||
return [ | ||
'dart', | ||
return ProcessInstructions('dart', [ | ||
'compile', | ||
'js', | ||
sourceFile, | ||
'-O4', | ||
'-o', | ||
'out/$baseNameNoExt.production.js' | ||
]; | ||
]); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(to avoid duplication you could use
AotTarget.values
and their string representation)