fix(functions): use dart build cli for Dart function bundles - #10926
fix(functions): use dart build cli for Dart function bundles#10926demolaf wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Dart functions deployment process by transitioning from dart compile exe to dart build cli for building the Dart linux-x64 bundle. As a result, the executable path is updated to build/cli/linux_x64/bundle/bin/server, and the manual creation of the bin directory is removed. I have no feedback to provide.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10926 +/- ##
=======================================
Coverage ? 59.32%
=======================================
Files ? 638
Lines ? 41954
Branches ? 8539
=======================================
Hits ? 24891
Misses ? 15001
Partials ? 2062 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
2d8df26 to
77647b0
Compare
wandamora
left a comment
There was a problem hiding this comment.
It seems more changes are required for this to work.
-
Because
buildis in config.ignore, readdirRecursive () skips the entirefirebase-tools/src/deploy/functions/prepareFunctionsUpload.ts
Lines 109 to 117 in 91745b0
build/directory. The uploaded archive will omitbuild/cli/linux_x64/bundle/bin/serverand its companion native asset libraries (build/cli/linux_x64/bundle/lib/), causing Cloud Run deployments to fail at runtime. We would need to change the default ignore config for dart and also ensure thatbuild/cli/**files are discoverable before callingprepareFunctionUpload:firebase-tools/src/deploy/functions/prepare.ts
Lines 433 to 436 in 91745b0
To avoid archive bloat, we could change the ignored files to allowlist the bundle:
"ignore": [
".dart_tool",
"build/**",
"!build/cli/linux_x64/bundle/**"
]
bin/servershould be updated tobuild/in the .gitignore template:
|
Also, adding some test cases could be useful:
|
| const isDart = supported.runtimeIsLanguage(wantBuilds[codebase].runtime, "dart"); | ||
| const executablePaths = isDart ? ["bin/server"] : []; | ||
| const executablePaths = getExecutablePaths(wantBuilds[codebase].runtime); | ||
|
|
There was a problem hiding this comment.
So, for new projects using firebase init, we don't need to worry about excluding the build/ files now. However for existing users, they'll continue to have the build/ directory ignored (the template won't change for them. We may need to add some work around in prepare.ts, such as:
let uploadCfg = localCfg;
if (isDart && uploadCfg.ignore?.includes("build")) {
uploadCfg = {
...uploadCfg,
ignore: uploadCfg.ignore.filter((i) => i !== "build" && i !== "build/"),
};
}
const packagedSource = await prepareFunctionsUpload...
with a comment explaining why.
Closes #10591
Following the release of Dart 3.13.0, we can now cross-compile with
dart build cli(previously onlydart compile exesupported--target-os/--target-arch), which unblocks using build hooks for Dart functions.dart compile exeproduces a single ahead-of-time compiled executable and skips Dart's native build hooks, so functions depending on packages with native assets don't build correctly. Switching todart build cliruns those hooks and produces a proper bundle instead of a bare executable.This updates the Dart runtime delegate to invoke
dart build cliwith the same target/os/arch flags, and updatesprepare.tsto look for the resulting server executable at its new bundle path (build/cli/linux_x64/bundle/bin/server) instead ofbin/server.Related to firebase/firebase-functions-dart#201