-
-
Notifications
You must be signed in to change notification settings - Fork 170
feat: add flag controlling the default for use_execroot_entry_point #2837
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
Open
acozzette
wants to merge
9
commits into
aspect-build:main
Choose a base branch
from
acozzette:use-execroot-entry-point
base: main
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6f7657e
feat: add flag controlling the default for use_execroot_entry_point
acozzette ec171e0
Added more tests
acozzette 187d953
Update snapshots
acozzette 1776626
Add use_execroot_entry_point param on Next.js macros for compatibilit…
acozzette 5eef6ef
Add todo
acozzette d40860d
Added more documentation
acozzette ad678b4
Undo changes to js_run_devserver
acozzette 79c5671
Fix docs
acozzette 5cf589d
Fixed language about build flag
acozzette 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # use_execroot_entry_point | ||
|
|
||
| This page describes the `use_execroot_entry_point` option on `js_run_binary` | ||
| and provides guidance on when to use each value. | ||
|
|
||
| ## Background | ||
|
|
||
| When a `js_binary` is used as a tool in `js_run_binary`, Bazel runs it as a | ||
| build action on the exec platform. The execroot is the root of the build | ||
| sandbox; beneath it sits `bazel-out/`, which contains output directories for | ||
| both the exec and target configurations. The tool's sources can therefore appear | ||
| in up to three places: | ||
|
|
||
| - **Exec-platform bin** (`bazel-out/<exec-cfg>/bin/`): where build artifacts for | ||
| the exec platform land. | ||
| - **Runfiles tree** (`bazel-out/<exec-cfg>/bin/path/to/my_binary.runfiles/`): | ||
| where the tool's runtime dependencies (including `node_modules`) are | ||
| symlinked and made available to the build action. | ||
| - **Target-platform bin** (`bazel-out/<target-cfg>/bin/`): where the `srcs` of | ||
| the `js_run_binary` action land. | ||
|
|
||
| When Node.js resolves `require()`, it walks up the directory tree looking for | ||
| `node_modules`. If the working directory is somewhere that can see | ||
| `node_modules` from both the exec output tree and the runfiles tree, the same | ||
| package can resolve from two different paths, which can cause subtle bugs. | ||
|
|
||
| ## What `use_execroot_entry_point` does | ||
|
|
||
| **`use_execroot_entry_point = True` (the current default):** | ||
| The tool's runfiles are hoisted into `srcs`, which causes them to be rebuilt in | ||
| the target configuration and land in the target-platform bin directory. The | ||
| entry point used is the one in that output tree (the "execroot entry point"), | ||
| rather than the copy inside the runfiles symlink tree. With everything | ||
| consolidated in `bazel-out/<target-cfg>/bin/`, Node.js sees a single | ||
| `node_modules` tree. This can be the right choice for some frameworks such as | ||
| Next.js, which expects inputs and outputs to be in the same directory tree. | ||
|
|
||
| The tradeoff is that if the exec platform differs from the target platform (for | ||
| example, cross-compiling from macOS to Linux), target-platform artifacts such as | ||
| native Node.js addons are rebuilt for the target and may fail to run on the exec | ||
| platform. | ||
|
|
||
| **`use_execroot_entry_point = False`:** | ||
| The entry point used is the one from the runfiles tree. All code executed during | ||
| the build action runs from the runfiles tree, which avoids cross-platform | ||
| issues. However, you must ensure that any code executed during the build (for | ||
| example, JavaScript config files for tools like Webpack or Rspack) is a declared | ||
| dependency of the `js_binary` tool, not merely a source file passed to | ||
| `js_run_binary`. Config files in the `js_run_binary`'s `srcs` will land in the | ||
| target-platform bin directory and will therefore not be visible to the tool's | ||
| runfiles resolution. | ||
|
|
||
| ## Recommendation | ||
|
|
||
| We recommend setting `use_execroot_entry_point = False` wherever possible and | ||
| ensuring that all code executed during the build is declared as a dependency of | ||
| the `js_binary`. The main exception is Next.js and similar frameworks that | ||
| expect inputs and outputs in the same directory tree or that execute | ||
| target-platform code during the build, in which case `True` is required. | ||
|
|
||
| To disable `use_execroot_entry_point` by default, pass the build flag: | ||
|
|
||
| ``` | ||
| --@aspect_rules_js//js:use_execroot_entry_point=False | ||
| ``` | ||
|
|
||
| Individual targets can still override the flag by explicitly setting | ||
| `use_execroot_entry_point = True` or `use_execroot_entry_point = False`. | ||
|
|
||
| In a future major version, we will likely disable the `use_execroot_entry_point` | ||
| behavior by default. | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Maybe in a followup PR, but currently nothing actually links to this doc? Maybe #2852 needs to solve that as well?
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.
That's true, nothing links to this yet. Maybe in a followup I should bring back docs/README.md and point to the new file as part of fixing #2852?