Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
8f365a3b
Unverified
Commit
8f365a3b
authored
Jan 12, 2023
by
joshualitt
Committed by
GitHub
Jan 12, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[web] Update build to use generated JS runtime for Dart2Wasm. (#118359)
parent
947b694f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
25 deletions
+17
-25
web.dart
packages/flutter_tools/lib/src/build_system/targets/web.dart
+15
-20
wasm_bootstrap.dart
...ter_tools/lib/src/web/file_generators/wasm_bootstrap.dart
+1
-1
web_test.dart
...ols/test/general.shard/build_system/targets/web_test.dart
+0
-3
flutter_build_wasm_test.dart
...tools/test/integration.shard/flutter_build_wasm_test.dart
+1
-1
No files found.
packages/flutter_tools/lib/src/build_system/targets/web.dart
View file @
8f365a3b
...
@@ -334,6 +334,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
...
@@ -334,6 +334,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
@override
@override
List
<
Source
>
get
outputs
=>
const
<
Source
>[
List
<
Source
>
get
outputs
=>
const
<
Source
>[
Source
.
pattern
(
'{OUTPUT_DIR}/main.dart.wasm'
),
Source
.
pattern
(
'{OUTPUT_DIR}/main.dart.wasm'
),
Source
.
pattern
(
'{OUTPUT_DIR}/main.dart.mjs'
),
];
];
// TODO(jacksongardner): override `depfiles` once dart2wasm begins producing
// TODO(jacksongardner): override `depfiles` once dart2wasm begins producing
...
@@ -348,7 +349,9 @@ class WebReleaseBundle extends Target {
...
@@ -348,7 +349,9 @@ class WebReleaseBundle extends Target {
final
WebRendererMode
webRenderer
;
final
WebRendererMode
webRenderer
;
final
bool
isWasm
;
final
bool
isWasm
;
String
get
outputFileName
=>
isWasm
?
'main.dart.wasm'
:
'main.dart.js'
;
String
get
outputFileNameNoSuffix
=>
'main.dart'
;
String
get
outputFileName
=>
'
$outputFileNameNoSuffix${isWasm ? '.wasm' : '.js'}
'
;
String
get
wasmJSRuntimeFileName
=>
'
$outputFileNameNoSuffix
.mjs'
;
@override
@override
String
get
name
=>
'web_release_bundle'
;
String
get
name
=>
'web_release_bundle'
;
...
@@ -362,11 +365,13 @@ class WebReleaseBundle extends Target {
...
@@ -362,11 +365,13 @@ class WebReleaseBundle extends Target {
List
<
Source
>
get
inputs
=>
<
Source
>[
List
<
Source
>
get
inputs
=>
<
Source
>[
Source
.
pattern
(
'{BUILD_DIR}/
$outputFileName
'
),
Source
.
pattern
(
'{BUILD_DIR}/
$outputFileName
'
),
const
Source
.
pattern
(
'{PROJECT_DIR}/pubspec.yaml'
),
const
Source
.
pattern
(
'{PROJECT_DIR}/pubspec.yaml'
),
if
(
isWasm
)
Source
.
pattern
(
'{BUILD_DIR}/
$wasmJSRuntimeFileName
'
),
];
];
@override
@override
List
<
Source
>
get
outputs
=>
<
Source
>[
List
<
Source
>
get
outputs
=>
<
Source
>[
Source
.
pattern
(
'{OUTPUT_DIR}/
$outputFileName
'
),
Source
.
pattern
(
'{OUTPUT_DIR}/
$outputFileName
'
),
if
(
isWasm
)
Source
.
pattern
(
'{OUTPUT_DIR}/
$wasmJSRuntimeFileName
'
),
];
];
@override
@override
...
@@ -376,20 +381,20 @@ class WebReleaseBundle extends Target {
...
@@ -376,20 +381,20 @@ class WebReleaseBundle extends Target {
'web_resources.d'
,
'web_resources.d'
,
];
];
bool
shouldCopy
(
String
name
)
=>
// Do not copy the deps file.
(
name
.
contains
(
outputFileName
)
&&
!
name
.
endsWith
(
'.deps'
))
||
(
isWasm
&&
name
==
wasmJSRuntimeFileName
);
@override
@override
Future
<
void
>
build
(
Environment
environment
)
async
{
Future
<
void
>
build
(
Environment
environment
)
async
{
for
(
final
File
outputFile
in
environment
.
buildDir
.
listSync
(
recursive:
true
).
whereType
<
File
>())
{
for
(
final
File
outputFile
in
environment
.
buildDir
.
listSync
(
recursive:
true
).
whereType
<
File
>())
{
final
String
basename
=
globals
.
fs
.
path
.
basename
(
outputFile
.
path
);
final
String
basename
=
globals
.
fs
.
path
.
basename
(
outputFile
.
path
);
if
(!
basename
.
contains
(
outputFileName
))
{
if
(
shouldCopy
(
basename
))
{
continue
;
outputFile
.
copySync
(
}
environment
.
outputDir
.
childFile
(
globals
.
fs
.
path
.
basename
(
outputFile
.
path
)).
path
// Do not copy the deps file.
);
if
(
basename
.
endsWith
(
'.deps'
))
{
continue
;
}
}
outputFile
.
copySync
(
environment
.
outputDir
.
childFile
(
globals
.
fs
.
path
.
basename
(
outputFile
.
path
)).
path
);
}
}
if
(
isWasm
)
{
if
(
isWasm
)
{
...
@@ -533,16 +538,6 @@ class WebBuiltInAssets extends Target {
...
@@ -533,16 +538,6 @@ class WebBuiltInAssets extends Target {
}
}
if
(
isWasm
)
{
if
(
isWasm
)
{
final
String
dartSdkPath
=
globals
.
artifacts
!.
getArtifactPath
(
Artifact
.
engineDartSdkPath
);
final
File
dart2wasmRuntime
=
fileSystem
.
directory
(
dartSdkPath
)
.
childDirectory
(
'bin'
)
.
childFile
(
'dart2wasm_runtime.mjs'
);
final
String
targetPath
=
fileSystem
.
path
.
join
(
environment
.
outputDir
.
path
,
'dart2wasm_runtime.mjs'
);
dart2wasmRuntime
.
copySync
(
targetPath
);
final
File
bootstrapFile
=
environment
.
outputDir
.
childFile
(
'main.dart.js'
);
final
File
bootstrapFile
=
environment
.
outputDir
.
childFile
(
'main.dart.js'
);
bootstrapFile
.
writeAsStringSync
(
wasm_bootstrap
.
generateWasmBootstrapFile
());
bootstrapFile
.
writeAsStringSync
(
wasm_bootstrap
.
generateWasmBootstrapFile
());
}
}
...
...
packages/flutter_tools/lib/src/web/file_generators/wasm_bootstrap.dart
View file @
8f365a3b
...
@@ -13,7 +13,7 @@ String generateWasmBootstrapFile() {
...
@@ -13,7 +13,7 @@ String generateWasmBootstrapFile() {
let moduleInstance;
let moduleInstance;
try {
try {
const dartModulePromise = WebAssembly.compileStreaming(fetch("main.dart.wasm"));
const dartModulePromise = WebAssembly.compileStreaming(fetch("main.dart.wasm"));
dart2wasm_runtime = await import('
./
dart2wasm_runtime
.
mjs
');
dart2wasm_runtime = await import('
./
main
.
dart
.
mjs
');
moduleInstance = await dart2wasm_runtime.instantiate(dartModulePromise, {});
moduleInstance = await dart2wasm_runtime.instantiate(dartModulePromise, {});
} catch (exception) {
} catch (exception) {
console.error(`Failed to fetch and instantiate wasm module:
${exception}
`);
console.error(`Failed to fetch and instantiate wasm module:
${exception}
`);
...
...
packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart
View file @
8f365a3b
...
@@ -865,14 +865,11 @@ void main() {
...
@@ -865,14 +865,11 @@ void main() {
}));
}));
test
(
'wasm build copies and generates specific files'
,
()
=>
testbed
.
run
(()
async
{
test
(
'wasm build copies and generates specific files'
,
()
=>
testbed
.
run
(()
async
{
globals
.
fs
.
file
(
'bin/cache/dart-sdk/bin/dart2wasm_runtime.mjs'
)
.
createSync
(
recursive:
true
);
globals
.
fs
.
file
(
'bin/cache/flutter_web_sdk/canvaskit/canvaskit.wasm'
)
globals
.
fs
.
file
(
'bin/cache/flutter_web_sdk/canvaskit/canvaskit.wasm'
)
.
createSync
(
recursive:
true
);
.
createSync
(
recursive:
true
);
await
WebBuiltInAssets
(
globals
.
fs
,
globals
.
cache
,
true
).
build
(
environment
);
await
WebBuiltInAssets
(
globals
.
fs
,
globals
.
cache
,
true
).
build
(
environment
);
expect
(
environment
.
outputDir
.
childFile
(
'dart2wasm_runtime.mjs'
).
existsSync
(),
true
);
expect
(
environment
.
outputDir
.
childFile
(
'main.dart.js'
).
existsSync
(),
true
);
expect
(
environment
.
outputDir
.
childFile
(
'main.dart.js'
).
existsSync
(),
true
);
expect
(
environment
.
outputDir
.
childDirectory
(
'canvaskit'
)
expect
(
environment
.
outputDir
.
childDirectory
(
'canvaskit'
)
.
childFile
(
'canvaskit.wasm'
)
.
childFile
(
'canvaskit.wasm'
)
...
...
packages/flutter_tools/test/integration.shard/flutter_build_wasm_test.dart
View file @
8f365a3b
...
@@ -47,11 +47,11 @@ void main() {
...
@@ -47,11 +47,11 @@ void main() {
'web_wasm'
'web_wasm'
));
));
for
(
final
String
filename
in
const
<
String
>[
for
(
final
String
filename
in
const
<
String
>[
'dart2wasm_runtime.mjs'
,
'flutter.js'
,
'flutter.js'
,
'flutter_service_worker.js'
,
'flutter_service_worker.js'
,
'index.html'
,
'index.html'
,
'main.dart.wasm'
,
'main.dart.wasm'
,
'main.dart.mjs'
,
'main.dart.js'
,
'main.dart.js'
,
])
{
])
{
expect
(
appBuildDir
.
childFile
(
filename
),
exists
);
expect
(
appBuildDir
.
childFile
(
filename
),
exists
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment