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(linux): native modules overwritten with wrong arch #8107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

megahertz
Copy link
Contributor

@megahertz megahertz commented Mar 7, 2024

Fixes: #7608

Description
When building an app for multiple Linux architectures, native modules are hardlinked to the modules in appDir/node_modules/**/*.node if CI env is set.

When the builder processes the first arch, it works fine. The second arch overwrites appDir/node_modules/**/*.node. Since these files are hardlinked to linux-*unpacked/resources/app.asar.unpacked/node_modules/**/*.node it overwrites native modules for all archs, so now the first arch distributive is broken.

FileCopier in builder-util/out/fs copies files by default, but once it detects a CI environment, it switches to hadlinking mode instead.

Example package.json which reproduces the issue
{
  "name": "builder-arm64-linux-issue",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "build": "env CI=1 electron-builder --linux --x64 --arm64 && find dist/linux-unpacked -name realm.node -exec file {} \\;"
  },
  "build": {
    "linux": {
      "target": {
        "arch": ["x64", "arm64"],
        "target": "dir"
      }
    }
  },
  "devDependencies": {
    "electron": "^29.1.0",
    "electron-builder": "^24.13.3"
  },
  "dependencies": {
    "realm": "^12.6.2"
  }
}

Copy link

changeset-bot bot commented Mar 7, 2024

🦋 Changeset detected

Latest commit: 702a291

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
app-builder-lib Patch
dmg-builder Patch
electron-builder-squirrel-windows Patch
electron-builder Patch
electron-forge-maker-appimage Patch
electron-forge-maker-nsis-web Patch
electron-forge-maker-nsis Patch
electron-forge-maker-snap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Mar 7, 2024

Deploy Preview for car-park-attendant-cleat-11576 ready!

Name Link
🔨 Latest commit 702a291
🔍 Latest deploy log https://app.netlify.com/sites/car-park-attendant-cleat-11576/deploys/65e9c4955c328900082c2449
😎 Deploy Preview https://deploy-preview-8107--car-park-attendant-cleat-11576.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mmaietta
Copy link
Collaborator

mmaietta commented Mar 8, 2024

I'm wary of this change as I'm assuming the owner/author of this project had a reason for not having hard links always disabled.
For your local project, why not use env var USE_HARD_LINKS=false?

@megahertz
Copy link
Contributor Author

I'm wary of this change as I'm assuming the owner/author of this project had a reason for not having hard links always disabled. For your local project, why not use env var USE_HARD_LINKS=false?

It's faster to use hardlinks instead of copying. But this change affects only *.node files inside app.asar.unpacked, so it can't impact performance too much. Anyway, it would be nice to ask @develar whether there are some pitfalls or hadrlinks are used only for speed reasons.

Sure, I use this env as a workaround. But it took pretty much time for me to find the reason of this issue, so it would be nice to include this fix by default.

@megahertz
Copy link
Contributor Author

Maybe it makes sense to disable hardlinking on the Linux build only since there is no such issue on macOS build?

@mmaietta
Copy link
Collaborator

mmaietta commented Mar 8, 2024

I really need @develar to chime in before moving forward with this PR. I do understand the need to resolve this issue, but I don't have the historical context to understand the reasoning for it to be disabled by default.

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

Successfully merging this pull request may close these issues.

electron-builder: Linux deb ,rpm arch cross-complile wont work. arm64 target contains x64 binaries
2 participants