yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Support --arch and --target_arch to build modules for other architectures

Open nsgundy opened this issue 8 years ago • 15 comments

Do you want to request a feature or report a bug? Feature

What is the current behavior? Not able to pass parameters so that yarn can be told to build packages for a specific architecture. Right now, in order to build for a specific target other than the architecture of the machine yarn is executed on, one has to run (example given to compile for arm):

yarn --production --ignore-scripts
npm rebuild --arch=arm --target_arch=arm

What is the expected behavior? Ability to pass --arch and --target_arch that yarn would then pass on to node-gyp, so that the above example would turn into:

yarn --production --arch=arm --target_arch=arm

Please mention your node.js, yarn and operating system version. node v6.9.1 yarn 0.17.10 Ubuntu 14.04

nsgundy avatar Dec 11 '16 00:12 nsgundy

+1

duncanfinney avatar Mar 24 '17 15:03 duncanfinney

PR is welcome

bestander avatar May 23 '17 16:05 bestander

This should be resolved now. Cross-compiling is available by setting the npm_config_arch environment variable.

SteveDesmond-ca avatar Sep 10 '18 18:09 SteveDesmond-ca

That aside it would also be great to support --target_platform, e.g. --target_platform=linux to be able for example to natively build a docker container on osx. Or is it possible to set a env variable for that also?

Globegitter avatar Feb 17 '19 21:02 Globegitter

https://docs.npmjs.com/misc/config theoretically if npm has a flag for it, you can set the env var the same way, e.g. something like npm_config_platform=linux

SteveDesmond-ca avatar Feb 17 '19 21:02 SteveDesmond-ca

Can someone explain is this still an issue? If not, how can we set arch for installation?

node-sass installations on M1 Macs are a problem now. And I couldn't figure out how to fix this with Yarn. npm workaround shared here works well: https://github.com/sass/node-sass/issues/3033#issuecomment-763180778

muratcorlu avatar Jun 24 '21 08:06 muratcorlu

@muratcorlu as mentioned above, set npm_config_arch environment variable for your target arch when installing your node_modules. For your case of M1 this would be arm64.

AndrewMuise avatar Jun 24 '21 18:06 AndrewMuise

@AndrewMuise No, actually I'm trying to install node-sass with x64 target since it doesn't build with arm64 for now. With npm, this works:

npm install --target_arch=x64

I tried to run NPM_CONFIG_ARCH=x64 yarn command but didn't work. Am I missing something?

muratcorlu avatar Jun 24 '21 23:06 muratcorlu

It's case sensitive, all lowercase, I know that doesn't follow env var convention but I think it was so args would match better

SteveDesmond-ca avatar Jun 24 '21 23:06 SteveDesmond-ca

I couldn't make it. Both npm_config_arch=x64 npm i and npm_config_arch=x64 yarn doesn't affect anything.

I try with Node 16 on an M1 Mac Mini with Big Sur.

Can you give an official document link about this env variable? I don't see an arch config parameter here: https://docs.npmjs.com/cli/v7/using-npm/config

muratcorlu avatar Jun 25 '21 10:06 muratcorlu

@muratcorlu, From the Windows command line, I'm doing this:

SET "npm_config_arch=xxxxx" && SET "npm_config_platform=xxxxx" && yarn install

That seems to work when I'm installing electron, at least.

Not sure how to set environment variables on Mac command line, but I think the concept should be similar 🙂

Eli-Black-Work avatar Jul 01 '21 08:07 Eli-Black-Work

@muratcorlu npm_config_arch env is recognized by node-gyp. See https://github.com/nodejs/node-gyp/blob/master/README.md#configuration

Also, there is npm_config_target_arch that is recognized by node-pre-gyp.

uasi avatar Jul 14 '21 10:07 uasi

Here are 2 options for npm and yarn to specify arch, platform and libc

npm install --target_arch=arm64 --target_platform=linux --target_libc=glibc
npm_config_target_arch=arm64 npm_config_target_platform=linux npm_config_target_libc=glibc yarn instal

h-grig avatar Jun 28 '22 16:06 h-grig

@h-grig is there a similar option for parcel? right now, cross-compiling from x86_64-musl to aarch64 fails for a project that uses first node-gyp and then parcel:

=> chronograf-1.10.1_1: running pre_build ...
cd ui && yarn --no-progress --no-emoji
yarn install v1.22.18
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "workspace-aggregator-8ca6dd9e-a42f-4d40-8c1f-d1d6b4e21f81 > chronograf-ui > [email protected]" has incorrect peer dependency "cypress@^4.5.0".
warning "workspace-aggregator-8ca6dd9e-a42f-4d40-8c1f-d1d6b4e21f81 > chronograf-ui > [email protected]" has incorrect peer dependency "react@>=^16.0.0".
warning "workspace-aggregator-8ca6dd9e-a42f-4d40-8c1f-d1d6b4e21f81 > chronograf-ui > [email protected]" has incorrect peer dependency "react-dom@>=^16.0.0".
warning "workspace-aggregator-8ca6dd9e-a42f-4d40-8c1f-d1d6b4e21f81 > chronograf-ui > cypress-image-snapshot > [email protected]" has incorrect peer dependency "jest@>=20 <=26".
[4/4] Building fresh packages...
$ echo "" > ../node_modules/go.mod
Done in 54.08s.
cd ui && yarn run clean && yarn run build
yarn run v1.22.18
$ rm -rf ./build/* && rm -rf ./.cache ../.parcel-cache
Done in 0.12s.
yarn run v1.22.18
$ APP_VERSION=$npm_package_version GIT_SHA=$(git rev-parse HEAD) parcel build --log-level error
fatal: not a git repository (or any of the parent directories): .git
Error: Error loading shared library ld-linux-aarch64.so.1: No such file or directory (needed by /builddir/chronograf-1.10.1/node_modules/@parcel/watcher/build/Release/watcher.node)
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1249:18)
    at Module.load (node:internal/modules/cjs/loader:1043:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1067:19)
    at require (/builddir/chronograf-1.10.1/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at load (/builddir/chronograf-1.10.1/node_modules/node-gyp-build/index.js:22:10)
    at Object.<anonymous> (/builddir/chronograf-1.10.1/node_modules/@parcel/watcher/index.js:1:104)
    at Module._compile (/builddir/chronograf-1.10.1/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
    at Module.load (node:internal/modules/cjs/loader:1043:32) {
  code: 'ERR_DLOPEN_FAILED'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
make: *** [Makefile:62: .jssrc] Error 1
=> ERROR: chronograf-1.10.1_1: pre_build: 'npm_config_arch=arm64 CFLAGS="$CFLAGS -fPIC" CXXFLAGS="$CXXFLAGS -fPIC" make .jsdep assets' exited with 2

dkwo avatar Apr 27 '23 15:04 dkwo