Skip to content

Commit 2301ecb

Browse files
authored
Generate app snapshots for the current OS (#224)
Might as well give some subset of our users a speed-up while we wait for dart-lang/sdk#28617.
1 parent 00be142 commit 2301ecb

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

tool/app-snapshot-input.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file is used to train application snapshots. It exercises the Sass value
2+
// types and the most common AST types so that they're already JIT-compiled when
3+
// the snapshot begins running.
4+
5+
/* loud comment */
6+
7+
@media screen {
8+
type {
9+
&.class#id[attr]%placeholder:pseudo {
10+
number: 1.5px;
11+
color: #abc;
12+
list: 1 2 3;
13+
map: map-get((1: 2), 1);
14+
string: foo;
15+
boolean: true;
16+
null: null;
17+
}
18+
}
19+
}
20+
21+
* {@extend %placeholder}

tool/grind.dart

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ bool get _isDevSdk => _dartVersion.isPreRelease;
3535
/// The root of the Dart SDK.
3636
final _sdkDir = p.dirname(p.dirname(Platform.resolvedExecutable));
3737

38+
/// Whether we're using a 64-bit Dart SDK.
39+
bool get _is64Bit => Platform.version.contains("x64");
40+
3841
main(List<String> args) => grind(args);
3942

4043
@DefaultTask('Compile async code and reformat.')
@@ -49,22 +52,32 @@ format() {
4952
..addAll(existingSourceDirs.map((dir) => dir.path)));
5053
}
5154

52-
@Task('Build Dart snapshot.')
55+
@Task('Build Dart script snapshot.')
5356
snapshot() {
5457
_ensureBuild();
5558
Dart.run('bin/sass.dart', vmArgs: ['--snapshot=build/sass.dart.snapshot']);
5659
}
5760

61+
@Task('Build Dart application snapshot.')
62+
appSnapshot() {
63+
_ensureBuild();
64+
Dart.run('bin/sass.dart',
65+
arguments: ['tool/app-snapshot-input.scss'],
66+
vmArgs: [
67+
'--snapshot=build/sass.dart.app.snapshot',
68+
'--snapshot-kind=app-jit'
69+
],
70+
quiet: true);
71+
}
72+
5873
@Task('Build standalone packages for all OSes.')
59-
@Depends(snapshot)
74+
@Depends(snapshot, appSnapshot)
6075
package() async {
6176
var client = new http.Client();
62-
await _buildPackage(client, "linux", "x64");
63-
await _buildPackage(client, "linux", "ia32");
64-
await _buildPackage(client, "macos", "x64");
65-
await _buildPackage(client, "macos", "ia32");
66-
await _buildPackage(client, "windows", "x64");
67-
await _buildPackage(client, "windows", "ia32");
77+
await Future.wait(["linux", "macos", "windows"].expand((os) => [
78+
_buildPackage(client, os, x64: true),
79+
_buildPackage(client, os, x64: false)
80+
]));
6881
client.close();
6982
}
7083

@@ -245,10 +258,12 @@ void _ensureBuild() {
245258
new Directory('build').createSync(recursive: true);
246259
}
247260

248-
/// Builds a standalone Sass package for the given [os] and [architecture].
261+
/// Builds a standalone Sass package for the given [os] and architecture.
249262
///
250263
/// The [client] is used to download the corresponding Dart SDK.
251-
Future _buildPackage(http.Client client, String os, String architecture) async {
264+
Future _buildPackage(http.Client client, String os, {bool x64: true}) async {
265+
var architecture = x64 ? "x64" : "ia32";
266+
252267
// TODO: Compile a single executable that embeds the Dart VM and the snapshot
253268
// when dart-lang/sdk#27596 is fixed.
254269
var channel = _isDevSdk ? "dev" : "stable";
@@ -267,13 +282,20 @@ Future _buildPackage(http.Client client, String os, String architecture) async {
267282
? file.name.endsWith("/bin/dart.exe")
268283
: file.name.endsWith("/bin/dart"));
269284
var executable = DelegatingList.typed<int>(dartExecutable.content as List);
285+
286+
// Use the app snapshot when packaging for the current operating system.
287+
//
288+
// TODO: Use an app snapshot everywhere when dart-lang/sdk#28617 is fixed.
289+
var snapshot = os == Platform.operatingSystem && x64 == _is64Bit
290+
? "build/sass.dart.app.snapshot"
291+
: "build/sass.dart.snapshot";
292+
270293
var archive = new Archive()
271294
..addFile(_fileFromBytes(
272295
"dart-sass/src/dart${os == 'windows' ? '.exe' : ''}", executable,
273296
executable: true))
274297
..addFile(_file("dart-sass/src/DART_LICENSE", p.join(_sdkDir, 'LICENSE')))
275-
..addFile(
276-
_file("dart-sass/src/sass.dart.snapshot", "build/sass.dart.snapshot"))
298+
..addFile(_file("dart-sass/src/sass.dart.snapshot", snapshot))
277299
..addFile(_file("dart-sass/src/SASS_LICENSE", "LICENSE"))
278300
..addFile(_fileFromString(
279301
"dart-sass/dart-sass${os == 'windows' ? '.bat' : ''}",

0 commit comments

Comments
 (0)