Visitar URL original
build: add GN build files by zcbenz · Pull Request #47637 · nodejs/node · GitHub
The Wayback Machine - https://web.archive.org/web/20231119092617/https://github.com/nodejs/node/pull/47637
Skip to content
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

build: add GN build files #47637

Merged
merged 1 commit into from Nov 11, 2023
Merged

build: add GN build files #47637

merged 1 commit into from Nov 11, 2023

Conversation

zcbenz
Copy link
Contributor

@zcbenz zcbenz commented Apr 20, 2023

As per discussion in nodejs/TSC#1353, this PR adds GN build files into Node's repo.

I have provided 2 ways to test the build:

  1. Build with a standalone version of GN.
  2. Build with depot_tools from Chromium.

Both have GitHub actions successfully building for win/mac/linux on arm/arm64/x64/x86.

This PR only adds configurations for building the node target, it does not include configurations for building tests, which I plan to add in a later PR, to make review easier.

After this is merged to Node, I'll upstream my changes in https://github.com/photoionization/node-ci to https://chromium.googlesource.com/v8/node-ci/, which is used by V8 team to test Node.js with latest V8. I'll also setup a nightly build of Node with gn in https://github.com/photoionization/node_with_gn, so we can find out early when the gn build is broken.

/cc @codebytere @victorgomes @joyeecheung @targos

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/http2
  • @nodejs/net
  • @nodejs/single-executable
  • @nodejs/url
  • @nodejs/wasi

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 20, 2023
tools/search_files.py Outdated Show resolved Hide resolved
deps/ada/BUILD.gn Outdated Show resolved Hide resolved
@gengjiawen
Copy link
Member

Maybe add gn setup to https://github.com/nodejs/node/blob/main/.gitpod.yml

With GN it is possible to reuse Chromium's sanitizers in Node, a full list of supported sanitizers can be found at: source.chromium.org/chromium/chromium/src/+/main:build/config/sanitizers/sanitizers.gni. They are very helpful tools for debugging various leaks and crashes.

Would be good since Node.js only have ASAN for now.

@targos
Copy link
Member

targos commented Apr 20, 2023

Does this attempt to build node with the same default config as with ./configure --ninja && make ?

@targos
Copy link
Member

targos commented Apr 20, 2023

I have depot_tools from Chromium on my PATH. How can I run the GN build?

@zcbenz
Copy link
Contributor Author

zcbenz commented Apr 20, 2023

Maybe add gn setup to https://github.com/nodejs/node/blob/main/.gitpod.yml

I didn't know gitpod, will give it a try.

@zcbenz
Copy link
Contributor Author

zcbenz commented Apr 20, 2023

Does this attempt to build node with the same default config as with ./configure --ninja && make ?

No, the GN config has some significant differences, for example it links with a custom libc++ statically. Eventually I would like to be able to build node with the same default config of gyp, but currently it is not my focus since neither V8 nor Electron needs it.

I have depot_tools from Chromium on my PATH. How can I run the GN build?

It uses the same workflow with checking out V8, the github action file has some instructions in it.

First checkout the code:

mkdir node-ci
cd node-ci
git clone https://github.com/photoionization/node-ci
gclient config https://github.com/photoionization/node-ci --unmanaged
gclient sync

Then you run gn and ninja:

cd node-ci
./tools/gn-gen.py out/Release
autoninja -C out/Release

Note that the https://github.com/photoionization/node-ci repo is a fork of https://chromium.googlesource.com/v8/node-ci/, the latter is used by V8 team to build Node with GN. I'll upstream the changes in my fork once GN configurations are merged into Node.

BUILD.gn Outdated Show resolved Hide resolved
@zcbenz zcbenz changed the title build: Add GN build files build: add GN build files Apr 24, 2023
@zcbenz zcbenz force-pushed the patch-gn branch 3 times, most recently from ff7e849 to b0a0174 Compare April 26, 2023 10:56
Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the GN files supposed to be used? Just gn args outdir and then run the build with ninja?

BUILD.gn Outdated Show resolved Hide resolved
deps/ada/BUILD.gn Outdated Show resolved Hide resolved
unofficial.gni Outdated Show resolved Hide resolved
@gengjiawen
Copy link
Member

Maybe add gn setup to main/.gitpod.yml

I didn't know gitpod, will give it a try.

create a .gitpod.Dockerfile in project root, and add deps to it

FROM gitpod/workspace-full

ENV PATH=${PATH}:/home/gitpod/depot_tools

RUN cd ~ && git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --depth=1

// other setup

Then in .gitpod.yml

image:
  file: .gitpod.Dockerfile

@zcbenz
Copy link
Contributor Author

zcbenz commented May 8, 2023

create a .gitpod.Dockerfile in project root, and add deps to it

Thanks for the guidance! I'll try to support it in a separate PR.

unofficial.gni Outdated Show resolved Hide resolved
deps/ada/unofficial.gni Outdated Show resolved Hide resolved
@zcbenz
Copy link
Contributor Author

zcbenz commented Sep 8, 2023

This PR has been rebased on main branch, currently it depends on #49178 and #49279.

@targos
Copy link
Member

targos commented Sep 11, 2023

#49279 just landed.

@joyeecheung
Copy link
Member

Is this ready for review now?

Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rubberstamp

@zcbenz zcbenz force-pushed the patch-gn branch 2 times, most recently from b1e3168 to e5e8579 Compare October 23, 2023 07:29
Copy link
Member

@Qard Qard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a doc equivalent to https://github.com/nodejs/node/blob/main/doc/contributing/building-node-with-ninja.md for this? Or does that not make sense in the state it is in currently? I feel like we should want people to be able to build with that method as soon as possible to avoid these files getting neglected and going out-of-sync with the rest of the build files.

@zcbenz
Copy link
Contributor Author

zcbenz commented Nov 6, 2023

@Qard Building with GN requires presence of a bunch of build configurations and tools, so I can not simply add a ./configuration --build-with-gn flag without introducing lots of non-simple dependencies into Node. Most projects building with GN has a DEPS file listing all required dependencies and uses gclient to synchronize them. V8 maintains a project that builds Node with GN, and you can see its DEPS file to get some ideas. Unless Node plans to officially support GN build, I think it would be too early to introduce these dependencies at current stage.

I maintains a fork of GN which ships necessary build configurations inside it, which can be used to build Node without using DEPS file and gclient tools, however it is not official and it is maintained by only me, so I'm not sure whether Node would be willing to include it in upstream.

Currently my plan for rolling out GN support in Node is:

  1. Merge GN build files into Node (i.e. this PR).
  2. Migrate V8's node-ci repo to use the new GN build files, which will make V8 team test the GN build files regularly. I already have finished the work migrating node-ci repo to use the new GN files: https://github.com/photoionization/node-ci.
  3. Setup a repo that does daily GN builds of Node: https://github.com/photoionization/node_with_gn. Electron team will do active maintenance to make sure the GN build does not break.
  4. Add docs to Node on how to build with GN using V8's node-ci repo and my fork of GN, and where to find unofficial binaries built with GN.
  5. Migrate Electron to use the GN files of Node.
  6. If there has been a wider acceptance of GN in Node developers, I will then implement ./configuration --build-with-gn in upstream Node.

In conclusion, I can add documentation on how to build Node with GN, but I think it is too early to do so in this PR.

@Qard
Copy link
Member

Qard commented Nov 6, 2023

I wasn't expecting a simple ./configure flag for it, I know there's extra things needed. I was just wondering if there could be a doc showing the various steps and dependencies, even if it's not something usable for most people yet. That can be reduced later if we simplify the process and integrate the tools more.

@zcbenz
Copy link
Contributor Author

zcbenz commented Nov 6, 2023

A document without using V8's node-ci repo or my forked GN would be mostly about how to write DEPS and .gclient files and how to use the raw gclient tools to synchronize code. GN itself is easy to use, it is just quite frustrating to fetch all the dependencies which change on very fast paces.

Relying on external tools can make the documentation focused only on important things, but to make those tools work with official Node repo we have to merge the GN build files first.

@anonrig
Copy link
Member

anonrig commented Nov 10, 2023 •

@zcbenz I'm adding simdjson as a dependency in a new pull request. Once it's landed, we need to add gn file for it as well.

Ref: #50322

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 11, 2023
@anonrig anonrig added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 11, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 11, 2023
@nodejs-github-bot
Copy link
Collaborator

@gengjiawen gengjiawen added the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 11, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 11, 2023
@nodejs-github-bot nodejs-github-bot merged commit 32af45d into nodejs:main Nov 11, 2023
54 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 32af45d

Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code wise LGTM but I have a question

Comment on lines +3 to +5
# Copyright 2023 Microsoft Inc.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What LICENSE file is this referring to? Do we need to check with the foundation about this?

@joyeecheung
Copy link
Member

oh I see that I am a bit too late to push the button. But I think we still need some clarification about the license.

@joyeecheung
Copy link
Member

joyeecheung commented Nov 11, 2023 •

I think what normally is done is an entry about tools/<whatever-new-file-added> needs to be added to the main LICENSE file found at the project directory, behind

https://github.com/nodejs/node/blob/83e6350b826a23b03417fd6978528aacace6c283/LICENSE#L49-52

otherwise the top-level license automatically applies to the files.

This PR however did not add anything to the LICENSE file. I am not a lawyer so I am not sure if this is a concern (it seems to be more of a concern for Microsoft than for us?). Not sure what needs to be done, cc @nodejs/tsc

targos pushed a commit that referenced this pull request Nov 11, 2023
PR-URL: #47637
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
@zcbenz
Copy link
Contributor Author

zcbenz commented Nov 12, 2023 •

The "BSD-style license" refers to Chromium's license.

The tools/generate_config_gypi.py, tools/search_files.py, and the GN build files are written from scratch up by Electron team and we can just delete their copyright headers to make Node's LICENSE file apply to them, like the other tools and gyps files in Node.

The tools/tools/gypi_to_gn.py is derived from Chromium so we must keep its copyright header, for which I'll need to add an entry in Node's LICENSE file.

I'll start a new PR correcting them.

targos pushed a commit that referenced this pull request Nov 14, 2023
PR-URL: #47637
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants