Skip to content

Commit

Permalink
[antlir2][package] fix cross-arch rpmbuild
Browse files Browse the repository at this point in the history
Summary:
Despite the fact that everything has already been compiled and we're just
stuffing blobs into an rpm, `rpmbuild` still whines if it doesn't think it's
able to cross-compile.

Test Plan:
```name="Before",counterexample
[[email protected] /data/sandcastle/boxes/fbsource (c4111eae6|remote/fbcode/warm_fbcode_od_stable...)]$ buck build -c fbcode.arch=aarch64 fbcode//registry/builder/rpm/tests:fb-rpm-builder-test.base--rpm
Action failed: fbcode//registry/builder/rpm/tests:fb-rpm-builder-test.base--rpm (antlir2_package)
Local command returned non-zero exit code 1
Reproduce locally: `env -- 'BUCK_SCRATCH_PATH=buck-out/v2/tmp/fbcode/8f66c3b3af22cefb/antlir2_package' buck-out/v2/gen/f ...<omitted>... ry/builder/rpm/tests/__fb-rpm-builder-test.base--rpm__/fb-rpm-builder-test.base--rpm.rpm' --rootless (run `buck2 log what-failed` to get the full command)`
stdout:
stderr:
Error: Failed to build rpm

Caused by:
    failed to run command env -i PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" TERM="xterm-256color" USER="root" container="antlir2" "/bin/rpmbuild" "-bb" "--define" "_rpmdir /__antlir2__/out" "--define" "_topdir /tmp/rpmbuild/top" "--define" "_tmppath /tmp/rpmbuild/tmp" "/tmp/rpmspec" (ExitStatus(unix_wait_status(256))):
    error: No compatible architectures found for build

Buck UI: https://www.internalfb.com/buck2/695cbb1c-6289-45c9-9b56-80a638de4481
Note:    Using experimental modern dice
Network: Up: 102KiB  Down: 160MiB  (reSessionID-324d094b-c7f9-4987-b3da-949edea03713)
Jobs completed: 152830. Time elapsed: 56.6s.
Cache hits: 95%. Commands: 1062 (cached: 1012, remote: 12, local: 38)
BUILD FAILED
Failed to build 'fbcode//registry/builder/rpm/tests:fb-rpm-builder-test.base--rpm (cfg:linux-arm64-fbcode-platform010-aarch64-asan-ubsan-dev#763c402bb95e0627)'
```

```
[[email protected] /data/sandcastle/boxes/fbsource
(c4111eae6|remote/fbcode/warm_fbcode_od_stable...)]$ buck build -c
fbcode.arch=aarch64
fbcode//registry/builder/rpm/tests:fb-rpm-builder-test.base--rpm --show-output
Buck UI: https://www.internalfb.com/buck2/8300ba3b-0e9a-4c92-9d44-820a0f173b62
Note:    Using experimental modern dice
Network: Up: 5.8KiB  Down: 122MiB  (reSessionID-5cef6928-9a6f-4d80-83d9-2f46ed2df1e3)
Jobs completed: 7. Time elapsed: 5.0s.
Cache hits: 0%. Commands: 2 (cached: 0, remote: 0, local: 2)
BUILD SUCCEEDED
fbcode//registry/builder/rpm/tests:fb-rpm-builder-test.base--rpm buck-out/v2/gen/fbcode/763c402bb95e0627/registry/builder/rpm/tests/__fb-rpm-builder-test.base--rpm__/fb-rpm-builder-test.base--rpm.rpm

[[email protected] /data/sandcastle/boxes/fbsource (27de4e028)]$ rpm -qpi buck-out/v2/gen/fbcode/763c402bb95e0627/registry/builder/rpm/tests/__fb-rpm-builder-test.base--rpm__/fb-rpm-builder-test.base--rpm.rpm
Name        : fb-rpm-builder-test.base
Epoch       : 0
Version     : 20240625
Release     : 073408
Architecture: aarch64
Install Date: (not installed)
Group       : Unspecified
Size        : 286
License     : Proprietary
Signature   : (none)
Source RPM  : fb-rpm-builder-test.base-20240625-073408.src.rpm
Build Date  : Tue 25 Jun 2024 07:34:08 AM PDT
Build Host  : antlir2
Packager    : registry
Summary     : For testing RPM builder
Description :
Built using rpm.builder for fbcode//registry/builder/rpm/tests:fb-rpm-builder-test.base
```

Reviewed By: naveedgol

Differential Revision: D59005434

fbshipit-source-id: fff9ceac6782bada64d83bbb8a4c1872af48f515
  • Loading branch information
vmagro authored and facebook-github-bot committed Jun 25, 2024
1 parent 31e2654 commit 92c4316
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions antlir/antlir2/antlir2_packager/src/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ impl PackageFormat for Rpm {
Epoch: {epoch}
Version: {version}
Release: {release}
BuildArch: {arch}
Summary: {summary}
License: {license}
Expand Down Expand Up @@ -238,8 +237,7 @@ AutoProv: {autoprov}

// create the arch-specific output dir explicitly so that it'll be
// owned by the build user on the host, not root
std::fs::create_dir(output_dir.path().join(&self.arch))
.context("while creating output dir")?;
std::fs::create_dir(output_dir.path().join(arch)).context("while creating output dir")?;

let mut isol_context = IsolationContext::builder(self.build_appliance.path());
isol_context
Expand All @@ -264,6 +262,8 @@ AutoProv: {autoprov}
unshare(isol_context.clone())?
.command("/bin/rpmbuild")?
.arg("-bb")
.arg("--target")
.arg(arch)
.arg("--define")
.arg("_rpmdir /__antlir2__/out")
.arg("--define")
Expand All @@ -277,7 +277,7 @@ AutoProv: {autoprov}

let outputs: Vec<_> = output_dir
.path()
.join(&self.arch)
.join(arch)
.read_dir()
.context("while reading rpm output dir")?
.filter_map(Result::ok)
Expand Down

0 comments on commit 92c4316

Please sign in to comment.