Skip to content

fix: cross-platform prebuild downloads - #1153

Merged
MarshallOfSound merged 7 commits into
electron:mainfrom
mmaietta:fix-prebuilt-binaries-target-platform
Oct 1, 2024
Merged

MarshallOfSound merged 7 commits into
electron:mainfrom
mmaietta:fix-prebuilt-binaries-target-platform

Conversation

@mmaietta

Copy link
Copy Markdown
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

codecov-commenter commented Sep 24, 2024 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.05%. Comparing base (cb372cd) to head (79d73e0).
Report is 35 commits behind head on main.

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/module-rebuilder.ts Resolved
Comment thread src/rebuild.ts Resolved
Co-authored-by: Erick Zhao <[email protected]>
@mmaietta

Copy link
Copy Markdown
Contributor Author

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

…/error. Added `platform` to `CacheOptions` cache key generation
@mmaietta

mmaietta commented Sep 24, 2024 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

Comment thread src/rebuild.ts Resolved

@samuelmaddock samuelmaddock left a comment

Copy link
Copy Markdown
Member

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
@mmaietta
mmaietta deleted the fix-prebuilt-binaries-target-platform branch October 1, 2024 15:48
@mmaietta

mmaietta commented Oct 1, 2024

Copy link
Copy Markdown
Contributor Author

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

@continuous-auth

Copy link
Copy Markdown

🎉 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