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?

@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>
@zcbenz zcbenz deleted the patch-gn branch November 28, 2023 01:57
UlisesGascon pushed a commit that referenced this pull request Dec 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>
@UlisesGascon UlisesGascon mentioned this pull request Dec 12, 2023
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
codebytere added a commit to electron/electron that referenced this pull request Jan 10, 2024
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