eve icon indicating copy to clipboard operation
eve copied to clipboard

[cross-compile] Make pkg/apparmor cross compilable

Open rucoder opened this issue 5 months ago • 3 comments

Description

Just for fun converted one of the packages into cross compilable. You can follow this pattern and do it for other packages as well. it may be tricky to run ./configure or figure out proper CFLAGS or install proper libraries into sysroot but it is possible

  • main trick is how sysroot is created. I'm using
FROM --platform=${TARGETPLATFORM} lfedge/eve-alpine:0f2e0da38e30753c68410727a6cc269e57ff74f2 as target-sysroot

and then we can install all required target libraries like

ENV BUILD_PKGS="musl-dev libgcc musl-libintl libintl  linux-headers"
RUN eve-alpine-deploy.sh
  • our cross compiler is broken and doesn't accept --sysroot however it is build with fixed --sysroot=/usr/x86_64-alpine-linux-musl for aarch64 so we just copy libraries from our sysrot to this location

How to test and validate this PR

docker buildx build --platform=linux/arm64 -t cross-test-1 --load .
docker run -it cross-test-1 /bin/bash

run file /usr/bin/apparmor_parser to make sure it is of aarch64 architecture.

repeat these steps for all other architectures

PR Backports

- 14.5-stable: No
- 13.4-stable: No

Checklist

  • [x] I've provided a proper description
  • [x] I've added the proper documentation
  • [ ] I've tested my PR on amd64 device
  • [ ] I've tested my PR on arm64 device
  • [x] I've written the test verification instructions
  • [x] I've set the proper labels to this PR

And the last but not least:

  • [x] I've checked the boxes above, or I've provided a good reason why I didn't check them.

Please, check the boxes above after submitting the PR in interactive mode.

rucoder avatar Jul 14 '25 19:07 rucoder

Isn't riscv64 missing?


You can follow this pattern

I don't think it is a good idea to copy all this lines to other packages. Isn't it possible to make it easier for other packages to adopt it?

christoph-zededa avatar Jul 15 '25 08:07 christoph-zededa

Isn't riscv64 missing?


You can follow this pattern

I don't think it is a good idea to copy all this lines to other packages. Isn't it possible to make it easier for other packages to adopt it?

It is, but apparmor is not a part of riscv build and we do not have a crosscompiler. Would be nice to move to clang which is cross compiler by default but it may be tricky to run configure if it doesn't support it

For the second question. It is possible to some extent like I did in lfedge/eve-rust but for rust you always have the same environment you want to set and for C it is always different. Besides having one more intermediate package is a pain. You need to update intermediate builder first and then your target package

rucoder avatar Jul 15 '25 09:07 rucoder

Isn't riscv64 missing?

You can follow this pattern

I don't think it is a good idea to copy all this lines to other packages. Isn't it possible to make it easier for other packages to adopt it?

It is, but apparmor is not a part of riscv build and we do not have a crosscompiler. Would be nice to move to clang which is cross compiler by default but it may be tricky to run configure if it doesn't support it

For the second question. It is possible to some extent like I did in lfedge/eve-rust but for rust you always have the same environment you want to set and for C it is always different. Besides having one more intermediate package is a pain. You need to update intermediate builder first and then your target package

We do have cross-compiler for riscv64 from hosts x86_64 and arm64. What we don't have is cross-compiler for x86_64 and arm64 from riscv64 hosts. If this image can be built for riscv64 without issues, let's add the cross-compilation for it as well. If it has issues (like pillar), then is not worth of change....

rene avatar Jul 16 '25 11:07 rene