-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide more examples for pkg_rpm() (#823)
* Move prebuilt_rpmbuild example into rpm subdirectory This will help us be a bit more organized as we add a few more RPM-based examples for rules_pkg. * Fix WORKSPACE file to account for subdirectory move One we moved this into a subdirectory it was broke because of how it uses rules_pkg as a local repository. * s/readme.md/README.md/ The latter seems to be more the norm, so renaming for consistency and visibility. * Add more detail to README.md for prebuilt_rpmbuild example This adds a bit more detail the description of the `prebuilt_rpmbuild` example so that someone can understand it a bit more. * Add an example of using system rpmbuild for pkg_rpm() This example is essentially the same as the prebuilt_rpmbuild example except that it uses find_system_rpmbuild() to register the local version of `rpmbuild` as the toolchain to use. * Add an example with bzlmod using system rpmbuild This is very similar to the non-bzlmod version except we've replaced the WORKSPACE file with a MODULE.bazel file. * Add an example that doesn't use a specfile for pkg_rpm() This example uses pkg_rpm() to generate the full rpm in lieu of using a standalone specfile.
- Loading branch information
Showing
19 changed files
with
343 additions
and
15 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# -*- coding: utf-8 -*- | ||
|
||
load("@rules_pkg//pkg:mappings.bzl", "pkg_files") | ||
load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm") | ||
|
||
pkg_files( | ||
name = "rpm_files", | ||
srcs = [ | ||
"BUILD", | ||
"MODULE.bazel", | ||
"README.md", | ||
], | ||
) | ||
|
||
pkg_rpm( | ||
name = "test-rpm", | ||
srcs = [ | ||
":rpm_files", | ||
], | ||
release = "0", | ||
version = "1", | ||
summary = "rules_pkg example RPM", | ||
description = "This is a package description.", | ||
license = "Apache License, v2.0", | ||
architecture = "x86_64", | ||
requires = [ | ||
"somerpm", | ||
], | ||
provides = [ | ||
"somefile", | ||
], | ||
) | ||
|
||
# If you have rpmbuild, you probably have rpm2cpio too. | ||
# Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain | ||
genrule( | ||
name = "inspect_content", | ||
srcs = [":test-rpm"], | ||
outs = ["content.txt"], | ||
cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
module(name = "rules_pkg_example_rpm_system_rpmbuild_bzlmod") | ||
|
||
bazel_dep(name = "rules_pkg") | ||
|
||
local_path_override( | ||
module_name = "rules_pkg", | ||
path = "../../..", | ||
) | ||
|
||
find_rpmbuild = use_extension( | ||
"@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", | ||
"find_system_rpmbuild_bzlmod", | ||
) | ||
use_repo(find_rpmbuild, "rules_pkg_rpmbuild") | ||
|
||
register_toolchains( | ||
"@rules_pkg_rpmbuild//:all", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Using system rpmbuild with bzlmod | ||
|
||
## Summary | ||
|
||
This example builds an RPM using the system `rpmbuild` from a pure bazel | ||
`pkg_rpm()` definition instead of using a separate specfile. | ||
|
||
## To use | ||
|
||
``` | ||
bazel build :* | ||
rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt | ||
cat bazel-bin/content.txt | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Using a prebuilt rpmbuild instead of the system one. | ||
|
||
## Summary | ||
|
||
This example defines a rpmbuild toolchain in `local` that can be used | ||
by rules_pkg. This must be copied into place as `local/rpmbuild_binary` | ||
for use by `register_toolchains()`. | ||
|
||
The RPM itself is based on a user provided spec file. | ||
|
||
## To use | ||
|
||
``` | ||
cp /usr/bin/rpmbuild local/rpmbuild_binary | ||
bazel build :* | ||
rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt | ||
cat bazel-bin/content.txt | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2020 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# -*- coding: utf-8 -*- | ||
|
||
load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm") | ||
|
||
pkg_rpm( | ||
name = "test-rpm", | ||
data = [ | ||
"BUILD", | ||
"WORKSPACE", | ||
"README.md", | ||
"test_rpm.spec", | ||
], | ||
release = "0", | ||
spec_file = "test_rpm.spec", | ||
version = "1", | ||
) | ||
|
||
# If you have rpmbuild, you probably have rpm2cpio too. | ||
# Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain | ||
genrule( | ||
name = "inspect_content", | ||
srcs = [":test-rpm"], | ||
outs = ["content.txt"], | ||
cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Using system rpmbuild | ||
|
||
## Summary | ||
|
||
This example uses the `find_system_rpmbuild()` macro built into `rules_pkg` | ||
to search for `rpmbuild` in on the local system and use that to drive the | ||
packaging process. | ||
|
||
The RPM itself is based on a user provided spec file. | ||
|
||
## To use | ||
|
||
``` | ||
bazel build :* | ||
rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt | ||
cat bazel-bin/content.txt | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
workspace(name = "rules_pkg_example_rpm_system_rpmbuild") | ||
|
||
local_repository( | ||
name = "rules_pkg", | ||
path = "../../..", | ||
) | ||
|
||
load("@rules_pkg//pkg:deps.bzl", "rules_pkg_dependencies") | ||
|
||
rules_pkg_dependencies() | ||
|
||
load( | ||
"@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", | ||
"find_system_rpmbuild", | ||
) | ||
|
||
find_system_rpmbuild(name="my_rpmbuild") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Name: example | ||
Version: 0 | ||
Release: 1 | ||
Summary: Example .spec file | ||
License: Apache License, v2.0 | ||
|
||
# Do not try to use magic to determine file types | ||
%define __spec_install_post %{nil} | ||
# Do not die because we give it more input files than are in the files section | ||
%define _unpackaged_files_terminate_build 0 | ||
|
||
%description | ||
This is a package description. | ||
|
||
%build | ||
|
||
%install | ||
cp WORKSPACE BUILD README.md test_rpm.spec %{buildroot}/ | ||
|
||
%files | ||
/WORKSPACE | ||
/BUILD | ||
/README.md | ||
/test_rpm.spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2020 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# -*- coding: utf-8 -*- | ||
|
||
load("@rules_pkg//pkg:rpm.bzl", "pkg_rpm") | ||
|
||
pkg_rpm( | ||
name = "test-rpm", | ||
data = [ | ||
"BUILD", | ||
"MODULE.bazel", | ||
"README.md", | ||
"test_rpm.spec", | ||
], | ||
release = "0", | ||
spec_file = "test_rpm.spec", | ||
version = "1", | ||
) | ||
|
||
# If you have rpmbuild, you probably have rpm2cpio too. | ||
# Feature idea: Add rpm2cpio and cpio to the rpmbuild toolchain | ||
genrule( | ||
name = "inspect_content", | ||
srcs = [":test-rpm"], | ||
outs = ["content.txt"], | ||
cmd = "rpm2cpio $(locations :test-rpm) | cpio -ivt >$@", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
module(name = "rules_pkg_example_rpm_system_rpmbuild_bzlmod") | ||
|
||
bazel_dep(name = "rules_pkg") | ||
|
||
local_path_override( | ||
module_name = "rules_pkg", | ||
path = "../../..", | ||
) | ||
|
||
find_rpmbuild = use_extension( | ||
"@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", | ||
"find_system_rpmbuild_bzlmod", | ||
) | ||
use_repo(find_rpmbuild, "rules_pkg_rpmbuild") | ||
|
||
register_toolchains( | ||
"@rules_pkg_rpmbuild//:all", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Using system rpmbuild with bzlmod | ||
|
||
## Summary | ||
|
||
This example uses the `find_system_rpmbuild_bzlmod` module extension to help | ||
us register the system rpmbuild as a toolchain in a bzlmod environment. | ||
|
||
The RPM itself is based on a user provided spec file. | ||
|
||
## To use | ||
|
||
``` | ||
bazel build :* | ||
rpm2cpio bazel-bin/test-rpm.rpm | cpio -ivt | ||
cat bazel-bin/content.txt | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Name: example | ||
Version: 0 | ||
Release: 1 | ||
Summary: Example .spec file | ||
License: Apache License, v2.0 | ||
|
||
# Do not try to use magic to determine file types | ||
%define __spec_install_post %{nil} | ||
# Do not die because we give it more input files than are in the files section | ||
%define _unpackaged_files_terminate_build 0 | ||
|
||
%description | ||
This is a package description. | ||
|
||
%build | ||
|
||
%install | ||
cp MODULE.bazel BUILD README.md test_rpm.spec %{buildroot}/ | ||
|
||
%files | ||
/MODULE.bazel | ||
/BUILD | ||
/README.md | ||
/test_rpm.spec |