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: cross-platform prebuild downloads #1153

Merged

Conversation

mmaietta
Copy link
Contributor

Allow prebuilt binaries to be downloaded for target platform instead of hardcoded process.platform. Throws an error when attempting to cross-compile (buildFromSource || no prebuilds found)
Example:

`--target_platform=${this.rebuilder.platform}`,

Origin of issue:

public platform: string = process.platform;

Updated interface with new platform option and added docs

…tead of hardcoded `process.platform`. Throws an error when attempting to cross-compile (`buildFromSource` || no prebuilds found)
@codecov-commenter
Copy link

codecov-commenter commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.05%. Comparing base (cb372cd) to head (79d73e0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1153      +/-   ##
==========================================
+ Coverage   76.93%   84.05%   +7.11%     
==========================================
  Files          21       21              
  Lines         763      765       +2     
  Branches      142      144       +2     
==========================================
+ Hits          587      643      +56     
+ Misses        122      121       -1     
+ Partials       54        1      -53     
Flag Coverage Δ
84.05% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/module-rebuilder.ts Outdated Show resolved Hide resolved
src/rebuild.ts Outdated Show resolved Hide resolved
Co-authored-by: Erick Zhao <[email protected]>
@mmaietta
Copy link
Contributor Author

Writing a few tests for the code coverage requirement. Stay tuned.

…/error. Added `platform` to `CacheOptions` cache key generation
@mmaietta
Copy link
Contributor Author

mmaietta commented Sep 24, 2024

Good thing I added tests. I had missed adding platform to the cache key.

I could use a tad bit of help though. (I'll continue investigating as well) I'm running into this test failure for the "early exit" when attempting cross-compilation via node-gyp.

  1 failing

  1) node-gyp
       buildArgs
         cross-compilation
           throws error early:
     AssertionError: expected [Function executor] to throw an error

Oddly enough, if I console.log right before the throw new Error, it logs the state correctly. So for some reason, expect(executor).throws() is not receiving the Error being thrown. Any idea why?

async rebuildModule(): Promise<void> {
if (this.rebuilder.platform !== process.platform) {
throw new Error("node-gyp does not support cross-compiling native modules from source")
}

const executor = () => nodeGyp.rebuildModule();
if (process.platform === platform) {
expect(executor).does.not.throw()
} else {
expect(executor).throws()
}

Example with logging:

    console.error("about to throw an error?", this.rebuilder.platform, process.platform)
    if (this.rebuilder.platform !== process.platform) {
      console.error("throw error")
      throw new Error("node-gyp does not support cross-compiling native modules from source")
    }
    console.error("I guess we build")

Logs in console show error logic is hit. Looks like something is swallowing the error?

about to throw an error? win32 darwin
throw error

Also, quick note, I changed platform: string to platform: NodeJS.Platform which shouldn't change much for the end user since platform was never configurable beforehand, so it just helps intellisense out for end users now.

@erickzhao erickzhao self-requested a review September 24, 2024 22:28
@mmaietta
Copy link
Contributor Author

Investigation update. It's throwing the error as written, but the event isn't propagating to mocha specifically. It properly logs the error being thrown if I add a .catch(console.error) to nodeGyp.rebuildModule(). I've taken a different approach in using an error message equality (to make sure we're testing this specific error being thrown) and then expect on a boolean flag

All tests are passing 🙃

const errorMessage = "node-gyp does not support cross-compiling native modules from source.";
let errorThrown = false;
await nodeGyp.rebuildModule().catch((err) => {
if (err.message === errorMessage) {
errorThrown = true
}
});
expect(errorThrown).to.be.true;

@MarshallOfSound
Copy link
Member

@mmaietta throws is used for synchronous checks, because the function you're calling is async you need to use the eventually assertion variants.

E.g. .to.eventually.be.rejectedWith (there are examples of this in other tests)

@mmaietta
Copy link
Contributor Author

Thanks @MarshallOfSound! I had overlooked the chaiAsPromised. Updated the test accordingly

src/rebuild.ts Outdated Show resolved Hide resolved
Copy link
Member

@samuelmaddock samuelmaddock left a comment

Choose a reason for hiding this comment

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

thanks for the added tests!

@MarshallOfSound MarshallOfSound merged commit 0bd2100 into electron:main Oct 1, 2024
3 checks passed
@mmaietta mmaietta deleted the fix-prebuilt-binaries-target-platform branch October 1, 2024 15:48
@mmaietta
Copy link
Contributor Author

mmaietta commented Oct 1, 2024

😞 Looks like this needed to be rebased off latest main since the eslint PR went in (or vice versa). My apologies

Copy link

🎉 This PR is included in version 3.6.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants