Skip to content

Pkg_rpm fails to build packages targeted to platforms other than the execution host machine. #727

@ogalbxela

Description

@ogalbxela

The current version of the "pkg_rpm" rule exposes an "architecture"-argument, which is meant to indicate the package's intended platform. It is being used to define the "BuildArch" option in the generated RPM spec file.
However, as per RPM packaging guide (https://rpm-packaging-guide.github.io/):
"'BuildArch' should be used if the package is not architecture dependent. For example, if written entirely in an interpreted programming language, set this to BuildArch: noarch. If not set, the package automatically inherits the Architecture of the machine on which it is built".

It appears that BuildArch is intended to represent either architecture of execution host machine or "noarch". Any efforts to designate an "alien" platform as a value for this field lead to a failure in the "rpmbuild"-utility, accompanied by an error message stating: "error: No compatible architectures found for build."

Possible solution to address this concern is to pass the value of "architecture"-argument to the "rpmbuild"-utility as the value for the "--target" option. However, it may break backward compatibility as "architecture"-argument might already be in use by someone who relies on current behavior. Introducing brand new "target_architecture"-argument may also be an option to consider.

Please consider possible fix #729. Please note that proposed patch attempts to address back compatibility concern.

Below is a "synthetic" example aimed to demonstrate concern. Note: in order to reduce sample size, I omitted cross compilation part just providing binary pre-compiled for aarch64.

Versions are: bazel: 6.0.0; rules_pkg: 0.9.1; host: ubuntu 20.04.2 x86_64; target: linux-aarch64

$ uname -a
Linux alexbl-dev-home 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ 
$ 
$ tree
.
├── src
│   ├── binary-aarch64
│   └── BUILD
└── WORKSPACE
$ 
$ 
$ file src/binary-aarch64 
src/binary-aarch64: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, not stripped
$ 
$ 
$ rpmbuild --version
RPM version 4.14.2.1
$ 
$ 
$ cat WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_pkg",
    sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
        "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
    ],
)
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()
load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")
find_system_rpmbuild(name = "rules_pkg_rpmbuild")
$ 
$ 
$ cat src/BUILD 
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")
load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm")

pkg_files(
    name = "sample-files",
    srcs = [":binary-aarch64"],
)

pkg_filegroup(
    name = "sample-data",
    srcs = [":sample-files"],
)

pkg_rpm(
    name = "sample-rpm",
    srcs = [":sample-data"],
    architecture = "aarch64",
    description = "Sample description",
    license = "Apache 2.0",
    release = "1",
    summary = "Sample summary",
    version = "1.0.0",
)
$ 
$ 
$ bazel build //src:sample-rpm 
INFO: Analyzed target //src:sample-rpm (46 packages loaded, 319 targets configured).
INFO: Found 1 target...
INFO: From MakeRpm src/sample-rpm-1.0.0-1.aarch64.rpm:
Error calling rpmbuild:
error: No compatible architectures found for build

No RPM file created.
ERROR: /home/dev/Projects/bazel/rpm_pkg_cross_demo/src/BUILD:14:8: output 'src/sample-rpm-1.0.0-1.aarch64.rpm' was not created
ERROR: /home/dev/Projects/bazel/rpm_pkg_cross_demo/src/BUILD:14:8: MakeRpm src/sample-rpm-1.0.0-1.aarch64.rpm failed: not all outputs were created or valid
Target //src:sample-rpm failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.913s, Critical Path: 0.15s
INFO: 11 processes: 10 internal, 1 linux-sandbox.
FAILED: Build did NOT complete successfully

sample.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that we are not working on but will review quarterlyrpm

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions