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

fix: ensure native modules use the correct config #35159

Merged
merged 2 commits into from Aug 1, 2022

Conversation

VerteDinde
Copy link
Member

Description of Change

Addresses #34885

In Electron 20, we modified how the config.gypi file was generated (it is now generated dynamically through a script). As part of that change, we need to ensure that any downstream users building native modules are using a current enough downstream version of node-gyp and electron-rebuild (a version containing at least this PR, e.g. >=8.4.0 for node-gyp and >=3.2.8 for electron-rebuild, particularly if they're using an alpha or beta).

This PR modifies the config.gypi and node files to add a warning to downstream module builders, ensuring they're on a high enough version. If the version is lower, native modules may successfully build, but will crash on unexpected ways to due missing includes.

Checklist

Release Notes

Notes: Adds a warning for building native modules with node-gyp and electron-rebuild, encouraging users to upgrade to >=8.4.0 for node-gyp and >=3.2.8 for electron-rebuild if using Electron 20 or higher..

MarshallOfSound and others added 2 commits July 29, 2022 17:00
This works by patching node.h to check that two defines are set using the equivilant of an XNOR operation.  One define "ELECTRON_ENSURE_CONFIG_GYPI" is set via common.gypi which is _already_ used to build native modules and has been since the dawn of time.  Therefore this define will be set for all native module compilations targetting the Electron runtime.  The second define "USING_ELECTRON_CONFIG_GYPI" is only defined when the gypi argument "using_electron_config_gypi" is set to 1 which is only done so via config.gypi.  Only new enough versions of node-gyp correctly use the config.gypi file thus resulting in a compilation error on version of node-gyp that are too old.
@VerteDinde VerteDinde requested review from a team as code owners August 1, 2022 14:16
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Aug 1, 2022
@VerteDinde VerteDinde added semver/patch backwards-compatible bug fixes blocks-release Releases shouldn't go out without this fix target/20-x-y labels Aug 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2022

electron-woa-testing

       2 files     910 suites   23m 4s ⏱️
2 127 tests 2 125 ✔️ 0 💤 2
2 413 runs  2 411 ✔️ 0 💤 2

For more details on these failures, see this check.

Results for commit 82921b8.

@VerteDinde VerteDinde merged commit 6c17dd2 into main Aug 1, 2022
@VerteDinde VerteDinde deleted the ensure-native-modules-use-config-gypi branch August 1, 2022 14:52
@release-clerk
Copy link

release-clerk bot commented Aug 1, 2022

Release Notes Persisted

Adds a warning for building native modules with node-gyp and electron-rebuild, encouraging users to upgrade to >=8.4.0 for node-gyp and >=3.2.8 for electron-rebuild if using Electron 20 or higher..

@trop
Copy link
Contributor

trop bot commented Aug 1, 2022

I have automatically backported this PR to "20-x-y", please check out #35160

schetle pushed a commit to schetle/electron that referenced this pull request Nov 3, 2022
* fix: ensure native modules are built with config.gypi

This works by patching node.h to check that two defines are set using the equivilant of an XNOR operation.  One define "ELECTRON_ENSURE_CONFIG_GYPI" is set via common.gypi which is _already_ used to build native modules and has been since the dawn of time.  Therefore this define will be set for all native module compilations targetting the Electron runtime.  The second define "USING_ELECTRON_CONFIG_GYPI" is only defined when the gypi argument "using_electron_config_gypi" is set to 1 which is only done so via config.gypi.  Only new enough versions of node-gyp correctly use the config.gypi file thus resulting in a compilation error on version of node-gyp that are too old.

* chore: fix lint

Co-authored-by: Samuel Attard <sattard@salesforce.com>
khalwa pushed a commit to solarwindscloud/electron that referenced this pull request Feb 22, 2023
* fix: ensure native modules are built with config.gypi

This works by patching node.h to check that two defines are set using the equivilant of an XNOR operation.  One define "ELECTRON_ENSURE_CONFIG_GYPI" is set via common.gypi which is _already_ used to build native modules and has been since the dawn of time.  Therefore this define will be set for all native module compilations targetting the Electron runtime.  The second define "USING_ELECTRON_CONFIG_GYPI" is only defined when the gypi argument "using_electron_config_gypi" is set to 1 which is only done so via config.gypi.  Only new enough versions of node-gyp correctly use the config.gypi file thus resulting in a compilation error on version of node-gyp that are too old.

* chore: fix lint

Co-authored-by: Samuel Attard <sattard@salesforce.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocks-release Releases shouldn't go out without this fix new-pr 🌱 PR opened in the last 24 hours semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants