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

Support for cross-platform RPM package generation #729

Open
wants to merge 1 commit into
base: 0.9.x
Choose a base branch
from

Conversation

ogalbxela
Copy link

@ogalbxela ogalbxela commented Aug 13, 2023

Please consider a patch aimed to add proper support for constructing RPM packages aimed for the CPU architecture other than the host machine. This addresses #727 issue.

The current version of the "pkg_rpm"-rule exposes an "architecture"-option, which is meant to indicate the package's intended platform. Unfortunately, this option is being incorrectly utilized. It is being used to define the "BuildArch"-option in the 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 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."

The purpose of this patch is to maintain backward compatibility while provide the solution for the described issue.
It preserves the existing "architecture"-attribute of the "pkg_rpm" rule, as it might already be in use by someone.
It introduces the "target_architecture"-attribute to the "pkg_rpm" rule, aiming to utilize it as a "arch"-suffix for the package name and to provide it to the "rpmbuild"-utility as the value for the "--target" option.

This change introduces proper support for generating RPM packages for the
designated target platform.

The current version of the "pkg_rpm"-rule exposes an "architecture"-option,
which is meant to indicate the package's intended platform.
Unfortunately, this option is being incorrectly utilized. It is being used to
define the "BuildArch"-option in the 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".

So, it sounds like it actually has nothing to do with target architecture. It is
supposed to represent either architecture of host machine or "noarch".

The purpose of this patch is to maintain backward compatibility while provide
the solution for the described issue.
It preserves the existing "architecture"-attribute of the "pkg_rpm" rule, as
it might already be in use by someone.
It introduces the "target_architecture"-attribute to the "pkg_rpm" rule, aiming
to utilize it as a "arch"-suffix for the package name and to provide it to the
"rpmbuild"-utility as the value for the "--target" option.
@aiuto
Copy link
Collaborator

aiuto commented Aug 14, 2023

Can we figure the right behavior out in the issue before jumping to code.
I'll comment there.

@ogalbxela
Copy link
Author

Can we figure the right behavior out in the issue before jumping to code. I'll comment there.

Thank you, Tony, I answered in the issue.

@@ -462,7 +467,10 @@ def main(argv):
help='The release of the software being packaged.')
parser.add_argument(
'--arch',
help='The CPU architecture of the software being packaged.')
help='The CPU architecture of the machine on which it is built. '
'If the package is not architecture dependent, set this to "noarch".')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this comment apply to targert_arch?

@@ -791,21 +794,30 @@ pkg_rpm = rule(
# funny if it's not provided. The contents of the RPM are believed to
# be set as expected, though.
"architecture": attr.string(
doc = """Package architecture.
doc = """Host architecture.

This currently sets the `BuildArch` tag, which influences the output
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop "currently" in these

@@ -791,21 +794,30 @@ pkg_rpm = rule(
# funny if it's not provided. The contents of the RPM are believed to
# be set as expected, though.
"architecture": attr.string(
doc = """Package architecture.
doc = """Host architecture.

This currently sets the `BuildArch` tag, which influences the output
architecture of the package.

Typically, `BuildArch` only needs to be set when the package is
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might as well make the exact behavior and use clear and tie it back to Bazel definitions when the terms overlap. The points to make are

  • If the package is really architecture independent, say "noarch"
  • Otherwise specify a CPU architecture of the target platform your are building for.
  • If you say nothing, it will default to the CPU arch of your execution platform.

Note that when cross compiling the target and execution platforms may not match.


When no attribute is provided, this will default to your host's
architecture. This is usually what you want.

""",
),
"target_architecture": attr.string(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both? I have not figured out the value of setting both, since only one gets used.

@aiuto aiuto added the P2 An issue that should be worked on when time is available label Nov 6, 2023
@aiuto
Copy link
Collaborator

aiuto commented Nov 6, 2023

Friendly ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 An issue that should be worked on when time is available
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants