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

[Bug]: Support for cross-compilation of pnpm packages with lifecycle #1225

Closed
sfc-gh-ptabor opened this issue Aug 22, 2023 · 0 comments · Fixed by #1226
Closed

[Bug]: Support for cross-compilation of pnpm packages with lifecycle #1225

sfc-gh-ptabor opened this issue Aug 22, 2023 · 0 comments · Fixed by #1226
Labels
bug Something isn't working untriaged Requires traige

Comments

@sfc-gh-ptabor
Copy link
Contributor

sfc-gh-ptabor commented Aug 22, 2023

(Propesed fix contributed in: #1226)

What happened?

I was prototyping installing sharp (https://sharp.pixelplumbing.com/) using bazel.
The created artifact (regardless of using --platform=... flag and constraints for linux) was being built for host's arch (darwin_arm64). I would like the artifact to be build for the requested architecture (driven by --platforms flag or field or transition).

In particular it led to a situation where the artifact couldn't be packed into docker image (using rules_oci), as the built module was for darwin. The node runtime embedded into image was proper, but the dependency was wrong:

.../examples/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/[email protected]/node_modules/sharp/build/Release/sharp-darwin-arm64r8.node

I will send for review a PR with an idea for a fix: #1226

Version

bazel --version
aspect 5.5.2
uname -a
Darwin.... 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64
http_archive(
    name = "aspect_rules_js",
    sha256 = "7b2a4d1d264e105eae49a27e2e78065b23e2e45724df2251eacdd317e95bfdfd",
    strip_prefix = "rules_js-1.31.0",
    url = "https://github.com/aspect-build/rules_js/releases/download/v1.31.0/rules_js-v1.31.0.tar.gz",
)

How to reproduce

load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_image_layer", "js_run_binary", "js_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@sfc_container_images_gcbi//:defs.bzl", "sfc_images_from_js_binary")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("//:blueprint.bzl", "BLUEPRINT")

npm_link_all_packages()

js_binary(
    name = "sharp",
    data = [
        "//node:node_modules/sharp",
    ],
    entry_point = "sharp.js",
)

platform(
    name = "linux_amd64",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
    ],
    visibility = ["//visibility:public"],
)

js_image_layer(
    name = "layers",
    binary = ":sharp",
    platform = ":linux_arm64",
    root = "/app",
    visibility = ["//visibility:__pkg__"],
)
% bazel build [--platforms=//node:linux_amd64] node:layers && tar -tvf bazel-bin/node/layers_node_modules.tar.gz | grep Release
INFO: Analyzed target //node:layers (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //node:layers up-to-date:
  bazel-bin/node/layers_app.tar.gz
  bazel-bin/node/layers_node_modules.tar.gz
INFO: Elapsed time: 0.337s, Critical Path: 0.07s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
drwxr-xr-x  0 0      0           0 Jan  1  1970 app/node/sharp.runfiles/sfc_container_images_examples/node_modules/.aspect_rules_js/[email protected]/node_modules/sharp/build/Release
-r-xr-xr-x  0 0      0      248264 Jan  1  1970 app/node/sharp.runfiles/sfc_container_images_examples/node_modules/.aspect_rules_js/[email protected]/node_modules/sharp/build/Release/sharp-darwin-arm64v8.node


### Any other information?

_No response_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged Requires traige
Projects
Archived in project
1 participant