11cb0ef41Sopenharmony_ci# Maintaining V8 in Node.js 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci## Background 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciV8 follows the Chromium release schedule. The support horizon for Chromium is 61cb0ef41Sopenharmony_cidifferent compared to the support horizon for Node.js. As a result, Node.js 71cb0ef41Sopenharmony_cineeds to support multiple versions of V8 longer than what upstream needs 81cb0ef41Sopenharmony_cito support. V8 branches in Node.js lack of an official maintenance process due 91cb0ef41Sopenharmony_cito a missing LTS supported branch. 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciThis document attempts to outline the current maintenance processes, proposes 121cb0ef41Sopenharmony_cia workflow for maintaining the V8 branches in both Node.js LTS and current 131cb0ef41Sopenharmony_cireleases, and discusses how the Node.js and V8 teams at Google can help. 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci## V8 release schedule 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciV8 and Chromium follow a 181cb0ef41Sopenharmony_ci[roughly 4-week release cadence][ChromiumReleaseCalendar]. At any given time 191cb0ef41Sopenharmony_cithere are several V8 branches that are **active**, see the 201cb0ef41Sopenharmony_ci[V8 release process](https://v8.dev/docs/release-process). All older branches 211cb0ef41Sopenharmony_ciare abandoned and are not maintained by the V8 team. 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci### V8 merge process overview 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciThe process for backporting bug fixes to active branches is officially 261cb0ef41Sopenharmony_cidocumented [on the V8 wiki][V8MergingPatching]. The summary of the process is: 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci* V8 only supports active branches. There is no testing done on any branches 291cb0ef41Sopenharmony_ci older than the current stable/beta/master. 301cb0ef41Sopenharmony_ci* A fix needing backport is tagged w/ _merge-request-x.x_ tag. This can be done 311cb0ef41Sopenharmony_ci by anyone interested in getting the fix backported. Issues with this tag are 321cb0ef41Sopenharmony_ci reviewed by the V8 team regularly as candidates for backporting. 331cb0ef41Sopenharmony_ci* Fixes need some 'baking time' before they can be approved for backporting. 341cb0ef41Sopenharmony_ci This means waiting a few days to ensure that no issues are detected on the 351cb0ef41Sopenharmony_ci canary/beta builds. 361cb0ef41Sopenharmony_ci* Once ready, the issue is tagged w/ _merge-approved-x.x_ and one can do the 371cb0ef41Sopenharmony_ci actual merge by using the scripts on the [wiki page][V8MergingPatching]. 381cb0ef41Sopenharmony_ci* Merge requests to an abandoned branch will be rejected. 391cb0ef41Sopenharmony_ci* Only bug fixes are accepted for backporting. 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci## Node.js support requirements 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ciAt any given time Node.js needs to be maintaining a few different V8 branches 441cb0ef41Sopenharmony_cifor the various Current, LTS, and nightly releases. 451cb0ef41Sopenharmony_ciThe versions of V8 used in Node.js may have already been 461cb0ef41Sopenharmony_ciabandoned by upstream V8. However, Node.js needs to continue supporting 471cb0ef41Sopenharmony_cithese branches for many months (Current branches) or several 481cb0ef41Sopenharmony_ciyears (LTS branches). 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci## Maintenance process 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ciOnce a bug in Node.js has been identified to be caused by V8, the first step is 531cb0ef41Sopenharmony_cito identify the versions of Node.js and V8 affected. The bug may be present in 541cb0ef41Sopenharmony_cimultiple different locations, each of which follows a slightly different 551cb0ef41Sopenharmony_ciprocess. 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci* Unfixed bugs. The bug exists in the V8 master branch. 581cb0ef41Sopenharmony_ci* Fixed, but needs backport. The bug may need porting to one or more branches. 591cb0ef41Sopenharmony_ci * Backporting to active branches. 601cb0ef41Sopenharmony_ci * Backporting to abandoned branches. 611cb0ef41Sopenharmony_ci* Backports identified by the V8 team. Bugs identified by upstream V8 that we 621cb0ef41Sopenharmony_ci haven't encountered in Node.js yet. 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci### Unfixed upstream bugs 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ciIf the bug can be reproduced on the [Node.js `canary` branch][], Chromium 671cb0ef41Sopenharmony_cicanary, or V8 tip-of-tree, and the test case is valid, then the bug needs to be 681cb0ef41Sopenharmony_cifixed upstream first. 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci* Start by opening a bug upstream using [this template][V8TemplateUpstreamBug]. 711cb0ef41Sopenharmony_ci* Make sure to include a link to the corresponding Node.js issue 721cb0ef41Sopenharmony_ci (if one exists). 731cb0ef41Sopenharmony_ci* If the fix is simple enough, you may fix it yourself; 741cb0ef41Sopenharmony_ci [contributions][V8Contributing] are welcome. 751cb0ef41Sopenharmony_ci* V8's build waterfall tests your change. 761cb0ef41Sopenharmony_ci* Once the bug is fixed it may still need backporting, if it exists in other V8 771cb0ef41Sopenharmony_ci branches that are still active or are branches that Node.js cares about. 781cb0ef41Sopenharmony_ci Follow the process for backporting below. 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci### Backporting to active branches 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ciIf the bug exists in any of the active V8 branches, we may need to get the fix 831cb0ef41Sopenharmony_cibackported. At any given time, there are [two active branches][V8ActiveBranches] 841cb0ef41Sopenharmony_ci(beta and stable) in addition to master. The following steps are needed to 851cb0ef41Sopenharmony_cibackport the fix: 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci* Identify which version of V8 the bug was fixed in. 881cb0ef41Sopenharmony_ci* Identify if any active V8 branches still contain the bug: 891cb0ef41Sopenharmony_ci* A tracking bug is needed to request a backport. 901cb0ef41Sopenharmony_ci * If there isn't already a V8 bug tracking the fix, open a new merge request 911cb0ef41Sopenharmony_ci bug using this [Node.js specific template][V8TemplateMergeRequest]. 921cb0ef41Sopenharmony_ci * If a bug already exists 931cb0ef41Sopenharmony_ci * Add a reference to the GitHub issue. 941cb0ef41Sopenharmony_ci * Attach _merge-request-x.x_ labels to the bug for any active branches 951cb0ef41Sopenharmony_ci that still contain the bug. 961cb0ef41Sopenharmony_ci* Once the merge has been approved, it should be merged using the 971cb0ef41Sopenharmony_ci [merge script documented in the V8 wiki][V8MergingPatching]. Merging requires 981cb0ef41Sopenharmony_ci commit access to the V8 repository. If you don't have commit access you can 991cb0ef41Sopenharmony_ci indicate someone on the V8 team can do the merge for you. 1001cb0ef41Sopenharmony_ci* It is possible that the merge request may not get approved, for example if it 1011cb0ef41Sopenharmony_ci is considered to be a feature or otherwise too risky for V8 stable. In such 1021cb0ef41Sopenharmony_ci cases we float the patch on the Node.js side. See the process on 'Backporting 1031cb0ef41Sopenharmony_ci to Abandoned branches'. 1041cb0ef41Sopenharmony_ci* Once the fix has been merged upstream, it can be picked up during an update of 1051cb0ef41Sopenharmony_ci the V8 branch (see below). 1061cb0ef41Sopenharmony_ci 1071cb0ef41Sopenharmony_ci### Backporting to abandoned branches 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ciAbandoned V8 branches are supported in the Node.js repository. The fix needs 1101cb0ef41Sopenharmony_cito be cherry-picked in the Node.js repository and V8-CI must test the change. 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ciAs an example for how to backport changes, consider the bug 1131cb0ef41Sopenharmony_ci[RegExp show inconsistent result with other browsers](https://crbug.com/v8/5199). 1141cb0ef41Sopenharmony_ciFrom the bug we can see that it was merged by V8 into 5.2 and 5.3, and not into 1151cb0ef41Sopenharmony_ciV8 5.1 (since it was already abandoned). Since Node.js `v6.x` uses V8 5.1, the 1161cb0ef41Sopenharmony_cifix needed to be backported. 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ci#### Backporting with `git-node` (recommended) 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_ciYou can use [`git-node`][] to help you backport patches. This removes 1211cb0ef41Sopenharmony_cisome manual steps and is recommended. 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ciHere are the steps for the bug mentioned above: 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_ci1. Install `git-node` by installing [`node-core-utils`][]. 1261cb0ef41Sopenharmony_ci2. Install the prerequisites for [`git-node-v8`][]. 1271cb0ef41Sopenharmony_ci3. Find the commit hash linked-to in the issue (in this case a51f429). 1281cb0ef41Sopenharmony_ci4. Checkout a branch off the appropriate _vY.x-staging_ branch (e.g. 1291cb0ef41Sopenharmony_ci _v6.x-staging_ to fix an issue in V8 5.1). 1301cb0ef41Sopenharmony_ci5. Run `git node v8 backport a51f429`. 1311cb0ef41Sopenharmony_ci6. If there are conflicts, `git-node` will wait for you to resolve them: 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci```console 1341cb0ef41Sopenharmony_ci$ git node v8 backport a51f429 1351cb0ef41Sopenharmony_ci✔ Update local V8 clone 1361cb0ef41Sopenharmony_ci❯ V8 commit backport 1371cb0ef41Sopenharmony_ci ✔ Get current V8 version 1381cb0ef41Sopenharmony_ci ✔ Generate patches 1391cb0ef41Sopenharmony_ci ❯ Apply and commit patches to deps/v8 1401cb0ef41Sopenharmony_ci ❯ Commit a51f429772d1 1411cb0ef41Sopenharmony_ci ⠏ Apply patch 1421cb0ef41Sopenharmony_ci ◼ Increment embedder version number 1431cb0ef41Sopenharmony_ci ◼ Commit patch 1441cb0ef41Sopenharmony_ci 1451cb0ef41Sopenharmony_ci? Resolve merge conflicts and enter 'RESOLVED' ‣ 1461cb0ef41Sopenharmony_ci``` 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_ciResolve conflicts, stage the files (you may need to open another terminal or use 1491cb0ef41Sopenharmony_cia GUI git client), then return to the terminal running `git-node`, type 1501cb0ef41Sopenharmony_ci`RESOLVED`, and hit <kbd>Enter</kbd>. 1511cb0ef41Sopenharmony_ci 1521cb0ef41Sopenharmony_ci7. After you resolve conflicts (or if there are no conflicts), the 1531cb0ef41Sopenharmony_ci output should look like this: 1541cb0ef41Sopenharmony_ci 1551cb0ef41Sopenharmony_ci```console 1561cb0ef41Sopenharmony_ci$ git node v8 backport a51f429 1571cb0ef41Sopenharmony_ci✔ Update local V8 clone 1581cb0ef41Sopenharmony_ci✔ V8 commit backport 1591cb0ef41Sopenharmony_ci``` 1601cb0ef41Sopenharmony_ci 1611cb0ef41Sopenharmony_ci8. Open a PR against the v6.x-staging branch in the Node.js repository. 1621cb0ef41Sopenharmony_ci Launch the normal and [V8 CI][] using the Node.js CI system. We only 1631cb0ef41Sopenharmony_ci needed to backport to v6.x as the other LTS branches weren't affected 1641cb0ef41Sopenharmony_ci by this bug. 1651cb0ef41Sopenharmony_ci 1661cb0ef41Sopenharmony_ciSee [`git-node-v8-backport`][] for more documentation and additional options. 1671cb0ef41Sopenharmony_ci 1681cb0ef41Sopenharmony_ci#### Backporting manually 1691cb0ef41Sopenharmony_ci 1701cb0ef41Sopenharmony_ci* For each abandoned V8 branch corresponding to an LTS branch that is affected 1711cb0ef41Sopenharmony_ci by the bug: 1721cb0ef41Sopenharmony_ci * Checkout a branch off the appropriate _vY.x-staging_ branch (e.g. 1731cb0ef41Sopenharmony_ci _v6.x-staging_ to fix an issue in V8 5.1). 1741cb0ef41Sopenharmony_ci * Cherry-pick the commit(s) from the V8 repository. 1751cb0ef41Sopenharmony_ci * Increase the `v8_embedder_string` number in `common.gypi`. 1761cb0ef41Sopenharmony_ci * In some cases the patch may require extra effort to merge in case V8 has 1771cb0ef41Sopenharmony_ci changed substantially. For important issues, we may be able to lean on the 1781cb0ef41Sopenharmony_ci V8 team to get help with reimplementing the patch. 1791cb0ef41Sopenharmony_ci * Open a cherry-pick pull request on `nodejs/node` targeting the 1801cb0ef41Sopenharmony_ci _vY.x-staging_ branch and notify the `@nodejs/v8` team. 1811cb0ef41Sopenharmony_ci * Run the Node.js [V8 CI][] in addition to the [Node.js CI][]. 1821cb0ef41Sopenharmony_ci The CI uses the `test-v8` target in the `Makefile`, which uses 1831cb0ef41Sopenharmony_ci `tools/make-v8.sh` to reconstruct a git tree in the `deps/v8` directory to 1841cb0ef41Sopenharmony_ci run V8 tests.[^1] 1851cb0ef41Sopenharmony_ci 1861cb0ef41Sopenharmony_ciHere are the steps for the bug mentioned above: 1871cb0ef41Sopenharmony_ci 1881cb0ef41Sopenharmony_ci* Download and apply the commit linked-to in the issue (in this case a51f429): 1891cb0ef41Sopenharmony_ci 1901cb0ef41Sopenharmony_ci ```console 1911cb0ef41Sopenharmony_ci curl -L https://github.com/v8/v8/commit/a51f429.patch | git am -3 --directory=deps/v8 1921cb0ef41Sopenharmony_ci ``` 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ci If the branches have diverged significantly, this may not apply cleanly. It 1951cb0ef41Sopenharmony_ci may help to try to cherry-pick the merge to the oldest branch that was done 1961cb0ef41Sopenharmony_ci upstream in V8. In this example, this would be the patch from the merge to 1971cb0ef41Sopenharmony_ci 5.2. The hope is that this would be closer to the V8 5.1, and has a better 1981cb0ef41Sopenharmony_ci chance of applying cleanly. 1991cb0ef41Sopenharmony_ci* Modify the commit message to match the format we use for V8 backports and 2001cb0ef41Sopenharmony_ci replace yourself as the author. `git commit --amend --reset-author`. You may 2011cb0ef41Sopenharmony_ci want to add extra description if necessary to indicate the impact of the fix 2021cb0ef41Sopenharmony_ci on Node.js. In this case the original issue was descriptive enough. Example: 2031cb0ef41Sopenharmony_ci 2041cb0ef41Sopenharmony_ci```console 2051cb0ef41Sopenharmony_cideps: cherry-pick a51f429 from V8 upstream 2061cb0ef41Sopenharmony_ci 2071cb0ef41Sopenharmony_ciOriginal commit message: 2081cb0ef41Sopenharmony_ci [regexp] Fix case-insensitive matching for one-byte subjects. 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_ci The bug occurs because we do not canonicalize character class ranges 2111cb0ef41Sopenharmony_ci before adding case equivalents. While adding case equivalents, we abort 2121cb0ef41Sopenharmony_ci early for one-byte subject strings, assuming that the ranges are sorted. 2131cb0ef41Sopenharmony_ci Which they are not. 2141cb0ef41Sopenharmony_ci 2151cb0ef41Sopenharmony_ci R=marja@chromium.org 2161cb0ef41Sopenharmony_ci BUG=v8:5199 2171cb0ef41Sopenharmony_ci 2181cb0ef41Sopenharmony_ci Review-Url: https://codereview.chromium.org/2159683002 2191cb0ef41Sopenharmony_ci Cr-Commit-Position: refs/heads/master@{#37833} 2201cb0ef41Sopenharmony_ci 2211cb0ef41Sopenharmony_ciRefs: https://github.com/v8/v8/commit/a51f429772d1e796744244128c9feeab4c26a854 2221cb0ef41Sopenharmony_ciPR-URL: https://github.com/nodejs/node/pull/7833 2231cb0ef41Sopenharmony_ci``` 2241cb0ef41Sopenharmony_ci 2251cb0ef41Sopenharmony_ci* Increase the `v8_embedder_string` number in `common.gypi`. 2261cb0ef41Sopenharmony_ci* Open a PR against the `v6.x-staging` branch in the Node.js repository. Launch 2271cb0ef41Sopenharmony_ci the normal and [V8 CI][] using the Node.js CI system. We only needed to 2281cb0ef41Sopenharmony_ci backport to `v6.x` as the other LTS branches weren't affected by this bug. 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ci### Backports identified by the V8 team 2311cb0ef41Sopenharmony_ci 2321cb0ef41Sopenharmony_ciFor bugs found through the browser or other channels, the V8 team marks bugs 2331cb0ef41Sopenharmony_cithat might be applicable to the abandoned branches in use by Node.js. This is 2341cb0ef41Sopenharmony_cidone through manual tagging by the V8 team and through an automated process that 2351cb0ef41Sopenharmony_citags any fix that gets backported to the stable branch (as it is likely 2361cb0ef41Sopenharmony_cicandidate for backporting further). 2371cb0ef41Sopenharmony_ci 2381cb0ef41Sopenharmony_ciSuch fixes are tagged with the following labels in the V8 issue tracker: 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_ci* `NodeJS-Backport-Review` ([V8][NodeJS-Backport-Review-V8], 2411cb0ef41Sopenharmony_ci [Chromium][NodeJS-Backport-Review-Chromium]): to be reviewed if this is 2421cb0ef41Sopenharmony_ci applicable to abandoned branches in use by Node.js. This list if regularly 2431cb0ef41Sopenharmony_ci reviewed by the Node.js team at Google to determine applicability to Node.js. 2441cb0ef41Sopenharmony_ci* `NodeJS-Backport-Approved` ([V8][NodeJS-Backport-Approved-V8], 2451cb0ef41Sopenharmony_ci [Chromium][NodeJS-Backport-Approved-Chromium]): marks bugs that are deemed 2461cb0ef41Sopenharmony_ci relevant to Node.js and should be backported. 2471cb0ef41Sopenharmony_ci* `NodeJS-Backport-Done` ([V8][NodeJS-Backport-Done-V8], 2481cb0ef41Sopenharmony_ci [Chromium][NodeJS-Backport-Done-Chromium]): Backport for Node.js has been 2491cb0ef41Sopenharmony_ci performed already. 2501cb0ef41Sopenharmony_ci* `NodeJS-Backport-Rejected` ([V8][NodeJS-Backport-Rejected-V8], 2511cb0ef41Sopenharmony_ci [Chromium][NodeJS-Backport-Rejected-Chromium]): Backport for Node.js is not 2521cb0ef41Sopenharmony_ci desired. 2531cb0ef41Sopenharmony_ci 2541cb0ef41Sopenharmony_ciThe backlog of issues with such is regularly reviewed by the node-team at Google 2551cb0ef41Sopenharmony_cito shepherd through the backport process. External contributors are welcome to 2561cb0ef41Sopenharmony_cicollaborate on the backport process as well. Some of the bugs may be 2571cb0ef41Sopenharmony_cisecurity issues and will not be visible to external collaborators. 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_ci## Updating V8 2601cb0ef41Sopenharmony_ci 2611cb0ef41Sopenharmony_ciNode.js keeps a vendored copy of V8 inside of the deps/ directory. In addition, 2621cb0ef41Sopenharmony_ciNode.js may need to float patches that do not exist upstream. This means that 2631cb0ef41Sopenharmony_cisome care may need to be taken to update the vendored copy of V8. 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ciV8 builds against the version of ICU supplied by Node.js, 2661cb0ef41Sopenharmony_cisee [maintaining-icu.md](./maintaining-icu.md) for special considerations. 2671cb0ef41Sopenharmony_ciSpecifically, a V8 update may necessitate an ICU update. 2681cb0ef41Sopenharmony_ci 2691cb0ef41Sopenharmony_ci### Minor updates (patch level) 2701cb0ef41Sopenharmony_ci 2711cb0ef41Sopenharmony_ciBecause there may be floating patches on the version of V8 in Node.js, it is 2721cb0ef41Sopenharmony_cisafest to apply the patch level updates as a patch. For example, imagine that 2731cb0ef41Sopenharmony_ciupstream V8 is at 5.0.71.47 and Node.js is at 5.0.71.32. It would be best to 2741cb0ef41Sopenharmony_cicompute the diff between these tags on the V8 repository, and then apply that 2751cb0ef41Sopenharmony_cipatch on the copy of V8 in Node.js. This should preserve the patches/backports 2761cb0ef41Sopenharmony_cithat Node.js may be floating (or else cause a merge conflict). 2771cb0ef41Sopenharmony_ci 2781cb0ef41Sopenharmony_ci#### Applying minor updates with `git-node` (recommended) 2791cb0ef41Sopenharmony_ci 2801cb0ef41Sopenharmony_ci1. Install [`git-node`][] by installing [`node-core-utils`][]. 2811cb0ef41Sopenharmony_ci2. Install the prerequisites for [`git-node-v8`][]. 2821cb0ef41Sopenharmony_ci3. Run `git node v8 minor` to apply a minor update. 2831cb0ef41Sopenharmony_ci 2841cb0ef41Sopenharmony_ciSee [`git-node-v8-minor`][] for more documentation and additional options. 2851cb0ef41Sopenharmony_ci 2861cb0ef41Sopenharmony_ci#### Applying minor updates manually 2871cb0ef41Sopenharmony_ci 2881cb0ef41Sopenharmony_ciThe rough outline of the process is: 2891cb0ef41Sopenharmony_ci 2901cb0ef41Sopenharmony_ci```bash 2911cb0ef41Sopenharmony_ci# Assuming your fork of Node.js is checked out in $NODE_DIR 2921cb0ef41Sopenharmony_ci# and you want to update the Node.js main branch. 2931cb0ef41Sopenharmony_ci# Find the current (OLD) version in 2941cb0ef41Sopenharmony_ci# $NODE_DIR/deps/v8/include/v8-version.h 2951cb0ef41Sopenharmony_cicd $NODE_DIR 2961cb0ef41Sopenharmony_cigit checkout main 2971cb0ef41Sopenharmony_cigit merge --ff-only origin/main 2981cb0ef41Sopenharmony_cigit checkout -b V8_NEW_VERSION 2991cb0ef41Sopenharmony_cicurl -L https://github.com/v8/v8/compare/${V8_OLD_VERSION}...${V8_NEW_VERSION}.patch | git apply --directory=deps/v8 3001cb0ef41Sopenharmony_ci# You may want to amend the commit message to describe the nature of the update 3011cb0ef41Sopenharmony_ci``` 3021cb0ef41Sopenharmony_ci 3031cb0ef41Sopenharmony_ciV8 also keeps tags of the form _5.4-lkgr_ which point to the _Last Known Good 3041cb0ef41Sopenharmony_ciRevision_ from the 5.4 branch that can be useful in the update process above. 3051cb0ef41Sopenharmony_ci 3061cb0ef41Sopenharmony_ci### Major updates 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_ciWe upgrade the version of V8 in Node.js `main` whenever a V8 release goes stable 3091cb0ef41Sopenharmony_ciupstream, that is, whenever a new release of Chrome comes out. 3101cb0ef41Sopenharmony_ci 3111cb0ef41Sopenharmony_ciUpgrading major versions would be much harder to do with the patch mechanism 3121cb0ef41Sopenharmony_ciabove. A better strategy is to 3131cb0ef41Sopenharmony_ci 3141cb0ef41Sopenharmony_ci1. Audit the current `main` branch and look at the patches that have been 3151cb0ef41Sopenharmony_ci floated since the last major V8 update. 3161cb0ef41Sopenharmony_ci2. Replace the copy of V8 in Node.js with a fresh checkout of the latest stable 3171cb0ef41Sopenharmony_ci V8 branch. Special care must be taken to recursively update the DEPS that V8 3181cb0ef41Sopenharmony_ci has a compile time dependency on (at the moment of this writing, these are 3191cb0ef41Sopenharmony_ci only trace\_event and gtest\_prod.h) 3201cb0ef41Sopenharmony_ci3. Reset the `v8_embedder_string` variable to "-node.0" in `common.gypi`. 3211cb0ef41Sopenharmony_ci4. Refloat (cherry-pick) all the patches from list computed in 1) as necessary. 3221cb0ef41Sopenharmony_ci Some of the patches may no longer be necessary. 3231cb0ef41Sopenharmony_ci 3241cb0ef41Sopenharmony_ciTo audit for floating patches: 3251cb0ef41Sopenharmony_ci 3261cb0ef41Sopenharmony_ci```bash 3271cb0ef41Sopenharmony_cigit log --oneline deps/v8 3281cb0ef41Sopenharmony_ci``` 3291cb0ef41Sopenharmony_ci 3301cb0ef41Sopenharmony_ciTo replace the copy of V8 in Node.js, use the [`git-node`][] tool. For example, 3311cb0ef41Sopenharmony_ciif you want to replace the copy of V8 in Node.js with the branch-head for V8 5.1 3321cb0ef41Sopenharmony_cibranch: 3331cb0ef41Sopenharmony_ci 3341cb0ef41Sopenharmony_ci```bash 3351cb0ef41Sopenharmony_cicd $NODE_DIR 3361cb0ef41Sopenharmony_cigit node v8 major --branch=5.1-lkgr 3371cb0ef41Sopenharmony_ci``` 3381cb0ef41Sopenharmony_ci 3391cb0ef41Sopenharmony_ciThis should be followed up with manual refloating of all relevant patches. 3401cb0ef41Sopenharmony_ci 3411cb0ef41Sopenharmony_ci## Proposal: Using a fork repository to track upstream V8 3421cb0ef41Sopenharmony_ci 3431cb0ef41Sopenharmony_ciThe fact that Node.js keeps a vendored, potentially edited copy of V8 in deps/ 3441cb0ef41Sopenharmony_cimakes the above processes a bit complicated. An alternative proposal would be to 3451cb0ef41Sopenharmony_cicreate a fork of V8 at `nodejs/v8` that would be used to maintain the V8 3461cb0ef41Sopenharmony_cibranches. This has several benefits: 3471cb0ef41Sopenharmony_ci 3481cb0ef41Sopenharmony_ci* The process to update the version of V8 in Node.js could be automated to track 3491cb0ef41Sopenharmony_ci the tips of various V8 branches in `nodejs/v8`. 3501cb0ef41Sopenharmony_ci* It would simplify cherry-picking and porting of fixes between branches as the 3511cb0ef41Sopenharmony_ci version bumps in `v8-version.h` would happen as part of this update instead of 3521cb0ef41Sopenharmony_ci on every change. 3531cb0ef41Sopenharmony_ci* It would simplify the V8-CI and make it more automatable. 3541cb0ef41Sopenharmony_ci* The history of the V8 branch in `nodejs/v8` becomes purer and it would make it 3551cb0ef41Sopenharmony_ci easier to pull in the V8 team for help with reviewing. 3561cb0ef41Sopenharmony_ci* It would make it simpler to setup an automated build that tracks Node.js 3571cb0ef41Sopenharmony_ci `main` + V8 lkgr integration build. 3581cb0ef41Sopenharmony_ci 3591cb0ef41Sopenharmony_ciThis would require some tooling to: 3601cb0ef41Sopenharmony_ci 3611cb0ef41Sopenharmony_ci* A script that would update the V8 in a specific Node.js branch with V8 from 3621cb0ef41Sopenharmony_ci upstream (dependent on branch abandoned vs. active). 3631cb0ef41Sopenharmony_ci* We need a script to bump V8 version numbers when a new version of V8 is 3641cb0ef41Sopenharmony_ci promoted from `nodejs/v8` to `nodejs/node`. 3651cb0ef41Sopenharmony_ci* Enabled the V8-CI build in Jenkins to build from the `nodejs/v8` fork. 3661cb0ef41Sopenharmony_ci 3671cb0ef41Sopenharmony_ci[^1]: On macOS, the V8 tests require a full Xcode install, not just the "command 3681cb0ef41Sopenharmony_ci line tools" for Xcode. 3691cb0ef41Sopenharmony_ci 3701cb0ef41Sopenharmony_ci[ChromiumReleaseCalendar]: https://www.chromium.org/developers/calendar 3711cb0ef41Sopenharmony_ci[Node.js CI]: https://ci.nodejs.org/job/node-test-pull-request/ 3721cb0ef41Sopenharmony_ci[Node.js `canary` branch]: https://github.com/nodejs/node-v8/tree/canary 3731cb0ef41Sopenharmony_ci[NodeJS-Backport-Approved-Chromium]: https://bugs.chromium.org/p/chromium/issues/list?can=1&q=label%3ANodeJS-Backport-Approved 3741cb0ef41Sopenharmony_ci[NodeJS-Backport-Approved-V8]: https://bugs.chromium.org/p/v8/issues/list?can=1&q=label%3ANodeJS-Backport-Approved 3751cb0ef41Sopenharmony_ci[NodeJS-Backport-Done-Chromium]: https://bugs.chromium.org/p/chromium/issues/list?can=1&q=label%3ANodeJS-Backport-Done 3761cb0ef41Sopenharmony_ci[NodeJS-Backport-Done-V8]: https://bugs.chromium.org/p/v8/issues/list?can=1&q=label%3ANodeJS-Backport-Done 3771cb0ef41Sopenharmony_ci[NodeJS-Backport-Rejected-Chromium]: https://bugs.chromium.org/p/chromium/issues/list?can=1&q=label%3ANodeJS-Backport-Rejected 3781cb0ef41Sopenharmony_ci[NodeJS-Backport-Rejected-V8]: https://bugs.chromium.org/p/v8/issues/list?can=1&q=label%3ANodeJS-Backport-Rejected 3791cb0ef41Sopenharmony_ci[NodeJS-Backport-Review-Chromium]: https://bugs.chromium.org/p/chromium/issues/list?can=1&q=label%3ANodeJS-Backport-Review 3801cb0ef41Sopenharmony_ci[NodeJS-Backport-Review-V8]: https://bugs.chromium.org/p/v8/issues/list?can=1&q=label%3ANodeJS-Backport-Review 3811cb0ef41Sopenharmony_ci[V8 CI]: https://ci.nodejs.org/job/node-test-commit-v8-linux/ 3821cb0ef41Sopenharmony_ci[V8ActiveBranches]: https://build.chromium.org/p/client.v8.branches/console 3831cb0ef41Sopenharmony_ci[V8Contributing]: https://v8.dev/docs/contribute 3841cb0ef41Sopenharmony_ci[V8MergingPatching]: https://v8.dev/docs/merge-patch 3851cb0ef41Sopenharmony_ci[V8TemplateMergeRequest]: https://bugs.chromium.org/p/v8/issues/entry?template=Node.js%20merge%20request 3861cb0ef41Sopenharmony_ci[V8TemplateUpstreamBug]: https://bugs.chromium.org/p/v8/issues/entry?template=Node.js%20upstream%20bug 3871cb0ef41Sopenharmony_ci[`git-node-v8-backport`]: https://github.com/nodejs/node-core-utils/blob/main/docs/git-node.md#git-node-v8-backport-sha 3881cb0ef41Sopenharmony_ci[`git-node-v8-minor`]: https://github.com/nodejs/node-core-utils/blob/main/docs/git-node.md#git-node-v8-minor 3891cb0ef41Sopenharmony_ci[`git-node-v8`]: https://github.com/nodejs/node-core-utils/blob/HEAD/docs/git-node.md#git-node-v8 3901cb0ef41Sopenharmony_ci[`git-node`]: https://github.com/nodejs/node-core-utils/blob/HEAD/docs/git-node.md#git-node-v8 3911cb0ef41Sopenharmony_ci[`node-core-utils`]: https://github.com/nodejs/node-core-utils#Install 392