We’re using the nodejs plugin to build apps based on Node.js. We want to build apps for linux arm64 architecture on linux amd64 systems (QEMU Linux amd64), but it seems the nodejs plugin has no cross-build capability (–target-arch=arm64).
Please could you verify this or tell us if there’s any way to setup? If not, do you plan to add this feature for future? Is there any documentation about the plugin available?
Thank you in advance.
This would also for me nice to know
1 Like
I could find a workaround using override-build doing same job than the plugin by just using the $SNAPCRAFT_TARGET_ARCH instead of the snapcraft’s own snap arch instead which simply solves this. So I think you could easily adapt this to your plugin by just changing static method _get_architecture() and replace the if/else by a simple arch switch/case.
This is the excerpt of my snapcraft.xml (we’re only interested in arm64/amd64:
plugin: nil
override-build: |
# set target arch
if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then
arch="arm64"
else
arch="x64"
fi
# fetch node
node_uri="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${arch}.tar.gz"
echo fetching: $node_uri
if [ ! -f "${SNAPCRAFT_PART_INSTALL}/bin/node" ]; then
curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1
fi
# pack and install the app
npm config set unsafe-perm true
npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --only=prod --production --no-fund