-
Notifications
You must be signed in to change notification settings - Fork 240
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
[RRFC] Support --cpu and --os flag to specify platform specific install #612
Comments
A package that requires a specific platform likely needs to be compiled for that platform. Why do you have the expectation that a package would work on a different one? |
@ljharb The main point here is |
@archfz well sure, but in that case wouldn't it declare the OS and CPU combos it was compatible with? I'm still unclear on why you'd want to pretend the platform is X, when it's Y - if the package works on Y, it'll declare it; if it doesn't, then it won't likely work even if you pretend it's X. |
@ljharb Building electron works something like this:
Now on step 2 the code can basically require 3rd party node packages. These packages are basically included as they are into the installer / executable. These packages can be native modules, and they can use the |
This feature request would achieve similar results as the |
This options are useful for building Docker image. In some cases, we want to run |
This PR allows `checkPlatform` to override execution environment which comes from `process.platform` and `process.arch` by default. This will be required to achieve npm/rfcs#612
How would this work with If I'm building on arm64, targeting x64 and have development dependencies with native modules, I'll likely need a mix. I think it would be better to have an |
An example of a native package where this does not apply can be found here: https://www.npmjs.com/package/@node-rs/crc32 This package, and others in the node-rs scope all have optional dependencies on a variety of packages for different os/cpu combinations. Each of these sub packages contain pre-compiled binaries. I myself have come to this issue after running in a problem that these flags would solve. Our macOS ARM64 CI builds on built on macOS x64 machines. This means that our CI builds fail to contain the darwin-arm64 dependency for crc32 (the linked package) because they instead install the darwin-x64 dependency. |
It looks like this has been closed due to npm/cli#6755 implementing what appears to be support for an installation tree that can work on a single alternative target platform/arch. However the comments made here and examples provided seem to be looking for an installation tree that can work on multiple platform/arch combinations, which is significantly more useful/powerful but perhaps more complex. Does this RFC cover multiarch? There is prior art for this in the supportedArchitectures feature of yarn. Most importantly, thank you all for your work on this so far, when complete it's going to make things so much easier for those of use who maintain native modules. |
Motivation ("The Why")
Given the
os
andcpu
package.json attributes, and the rise on usage ofoptionalDependencies
for native modules, and also given cross platform building of certain applications likeelectron
, it would be nice to be able to install npm packages for a given platform, disregarding current platform.Example
My case is having a thrid party native module using
optionalDependencies
to install platform specific node bindings for itself. One good example for this isnapi-rs
modules (see https://github.com/napi-rs/package-template). Now this module is bundled together with anelectron
app, and the build pipeline useswine
to build it for windows as well from debian. The issue is that the thrid party native module will always be installed withlinux
native bindings.How
Current Behaviour
Currently
optionalDependencies
only matching current platform will be installed, and it's not configurable.Desired Behaviour
The proposal is to have two extra possible arguments for
npm install
.--os
would specify for what operating system to install packages,--cpu
for what cpu. The defaults for these options would be from current platform.Example:
npm i --os win32 --cpu x64
References
The text was updated successfully, but these errors were encountered: