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

src: include specific V8 headers in node_v8 #40427

Closed
wants to merge 1 commit into from

Conversation

targos
Copy link
Member

@targos targos commented Oct 12, 2021

Refs: #39876

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. needs-ci PRs that need a full CI run. labels Oct 12, 2021
@targos
Copy link
Member Author

targos commented Oct 12, 2021

/cc @addaleax, @jasnell, @joyeecheung (I always miss that we don't have a @nodejs/c++ team :) )

What do you think about this in general? Should we try to migrate everything in src? This could be a relatively easy task for first contributions.
I suppose that we will not really benefit from it as long as node.h itself depends on v8.h?
I also suppose that removing the v8.h include from node.h is semver-major?

@jasnell
Copy link
Member

jasnell commented Oct 12, 2021

Ouch, that's going to make things more complicated. The only concern I'd have with this goes to ABI stability. In most headers I think we're fine but, as you mention, node.h is definitely problematic, and yes, it will likely need to be semver major.

@targos
Copy link
Member Author

targos commented Oct 12, 2021

If we think that the complexity is not worth the potential improvements, I can also close this and the referenced issue

@joyeecheung
Copy link
Member

I'd say doing internal cleanup is okay, we could probably use a guard behind NODE_WANT_INTERNALS in node.h eventually to make sure that we only use the smaller headers internally, but removing v8.h from node.h is definitely semver-major, and I agree that it would be problematic for user land addons.

Tangentially, is something similar being done to NAN headers?

src/cares_wrap.cc Outdated Show resolved Hide resolved
@targos targos changed the title src: include specific headers in cares_wrap src: include specific V8 headers in node_v8 Oct 14, 2021
@targos
Copy link
Member Author

targos commented Oct 14, 2021

@joyeecheung I tried to apply your suggestion. To do so, I started from another file that seemed more self-contained (I was wrong, it's not): node_v8.cc. I followed the dependency chain from this file and updated everything.

Tangentially, is something similar being done to NAN headers?

Not sure I understand the question. I am not involved in the NAN project.

src/node.h Outdated
#ifndef NODE_WANT_V8_SUBHEADERS
#include "v8.h"
#else
#include "v8-array-buffer.h"
Copy link
Member

Choose a reason for hiding this comment

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

With NODE_WANT_V8_SUBHEADERS, the list in the else clause should be empty - if node.h still includes the subheaders when NODE_WANT_V8_SUBHEADERS is defined, then node_v8.cc can still compile without including them specifically.

Copy link
Member Author

@targos targos Oct 14, 2021

Choose a reason for hiding this comment

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

Shouldn't we still include the headers that node.h needs? It seems wrong to have to do it from outside

Copy link
Member

Choose a reason for hiding this comment

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

Ah, right, we need this for the stuff in node.h too, I think in that case it should be fine to omit what's already in node.h in other files, too, since we've always been doing that

Copy link
Member Author

Choose a reason for hiding this comment

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

I just realized that we could also include v8-forward.h instead of the full headers. I'll investigate that
https://github.com/nodejs/node/blob/master/deps/v8/include/v8-forward.h

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated. Does it look better now?

@joyeecheung
Copy link
Member

Not sure I understand the question. I am not involved in the NAN project.

Just a general question since removing v8.h from node.h is mentioned, I figured if we do want to do that, starting from NAN might be a first step?

@targos targos marked this pull request as draft October 18, 2021 15:24
Also do it in all its dependencies.
This introduces the NODE_WANT_V8_SUBHEADERS macro to opt in
to only include specific V8 headers from our public ones (e.g. node.h).
@targos
Copy link
Member Author

targos commented May 3, 2022

I'll try to do it with https://include-what-you-use.org/ when I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants