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

Remove hard-coded architecture on Mac #141

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

savetheclocktower
Copy link
Sponsor Contributor

@savetheclocktower savetheclocktower commented Sep 9, 2024

Fixes #126.

We've known for a while about an issue where ppm rebuild fails to work properly on Apple Silicon. That command is run whenever a native module needs to be recompiled — either for a new processor architecture or for a new version of Electron — and there's even a GUI for it.

This is what it might look like for an end user, as it did for me last week when I got a new M3 MacBook Pro:

package-rebuilding-failure.mov

The built-in update-package-dependencies package is a frontend to ppm rebuild. Notice how it doesn't say “failed to rebuild the package”; it thinks it's succeeded, and yet after a window reload it once again flags the native module as being for the wrong architecture.

This was on my radar because some of pulsar-ide-python’s users had complained about it. zadeh was used in atom-languageclient — I moved away from it in my @savetheclocktower/atom-languageclient fork in order to work around this issue — so it affected a number of packages. It was strange to learn, then, that npm rebuild seemed not to be susceptible to this issue. This reduced it to an exercise in finding out exactly what the discrepancy was between ppm rebuild and npm rebuild.

For a few hours I was certain it was some sort of artifact of a too-old version of Node, NPM, or node-gyp. I noticed a behavior difference between two of my local versions of Node — 14.16.0 did the wrong thing, whereas 16.19.0 did the right thing — and I generally wasted my own time until I looked closely enough at the logging and traced the issue back to the PPM source itself.

PPM provides a bunch of build flags for NPM, processor architecture among them; on darwin it's been hard-coding x64 for years and years and years. I don't know why, but it was implemented in such a way that you couldn't even override it with an environment variable.

Removing the hard-coded special case seems to fix it for me. We should ensure it works as expected on an Intel Mac, but this feels like the obvious obvious obvious fix. I'm glad that it's as simple as this, though somewhat annoyed that I didn't notice it earlier.

Since neither ppm rebuild nor npm rebuild seems to need a subsequent pass through electron-rebuild, this should fix #126 altogether. (This might even make it so that (e.g.) ppm install autocomplete-paths installs the package properly the first time around; I'll check that next.) (Yeah, seems to work.)

I hope we can get this into the next release as a quality-of-life issue, but it can wait a month if people are nervous about it.

@DeeDeeG
Copy link
Member

DeeDeeG commented Sep 9, 2024

Commenting for posterity, since I already went through the trouble of tracing back in time through the blame view fully (following your lead), and posted it in the Discord... copy-pasting here for the historical record.

So, this code was from atom/apm#46 which... dubiously introduced the hard-coding, a9e5498 which fixed it for Linux/BSD (by not hard-coding on Linux or BSD), and then atom/apm#640 which fixed it for Windows by not hard-coding arch for Windows... and now we're not hard-coding it on macOS.

@savetheclocktower
Copy link
Sponsor Contributor Author

I noticed a behavior difference between two of my local versions of Node — 14.16.0 did the wrong thing, whereas 16.19.0 did the right thing

Oh, I forgot to mention: this is because I use asdf to manage my Node installations, and my 14.16.10 was built for x86_64. I had reinstalled most of my Nodes after migration, but not that one. (Just as well because there are no official arm64 builds of Node 14.)

Copy link
Member

@DeeDeeG DeeDeeG left a comment

Choose a reason for hiding this comment

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

tl;dr: FIX LOOKS GOOD TO ME. 👍

Long version:

Can confirm that, on my x64 (intel) MacBook, Node returns x64 when evaluating process.arch. Which matches what the hard-coded string would have been from the switch/case there was before this PR.

From that, and judging by the fact you're reporting this works for you on ARM (Apple Silicon), behavior as updated by this PR should absolutely be correct across x64 and ARM Macs alike now.

Given the history of un-hard-coding these values to solve issues over time, this fix falls along a long and steady line of the same fix being implemented individually for every major OS family. It only now comes back to macOS since they were the latest to diversify from one to multiple arches. (See my comment just above, as well as the note from your original PR post.)

So, the original hard-coding was not flexible enough, and thankfully we can do process.arch now. I have to guess/assume this wasn't available back in Node 0.11, and before Electron existed yet... So, maybe fudging the arch was important back when using Node in really non-standard ways??? Who knows?!

Also: By the way, this code is the only instance of ATOM_ARCH either in this repo or Pulsar core repo. So, I think it's just a convenient way to make ppm rebuild for a different arch. Might as well leave it, but I would be surprised if there are no real users of that env var, and the getElectronArch() function may be superfluous to simply using the process.arch method directly. But again, doesn't seem like a big deal to have this code path, might be nice to use in a pinch, and any users who did need it would (hypothetically???) probably sorely miss it. So, might as well keep it, I guess.

@savetheclocktower
Copy link
Sponsor Contributor Author

Yeah, I like the ability to specify ATOM_ARCH as an environment variable as an override just in case there is some weird scenario in which process.arch returns an unexpected value… or someone need to cross-compile.

@DeeDeeG DeeDeeG merged commit 97f4d20 into pulsar-edit:master Sep 9, 2024
11 checks passed
@DeeDeeG
Copy link
Member

DeeDeeG commented Sep 9, 2024

Very good to have this fix, thank you for the persistence in tracking this down!!

(Re-reading through #126 again, hindsight is 20/20, and this finding aligns with all of what was said there.)

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

Successfully merging this pull request may close these issues.

Add ability for PPM to run electron-rebuild automatically
2 participants