[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Building a package for arm64 only on amd64 machine



On 2024-01-14 20:31 +0000, David James wrote:
> Dear Mentors,
> 
> I am trying to package a small library that will be a dependency for a larger application. The thing is the library will only be a dependency if the application is built on arm64. The CMake file has the lines:
> if ("arm64" IN_LIST ARCHITECTURE)
> add_subdirectory(oaknut EXCLUDE_FROM_ALL)endif()
> 
> Oaknut is the library I'm trying to build. The problem stems from the fact that the tarball depends on the catch2, a package that contains Catch2WithMain.a. Oaknut won't build at all when I try to compile natively. When I try to cross compile to arm64 on my amd64 machine it gives me errors about relocations in ELF (62) related to /usr/lib/Catch2WithMain.a. I'm guessing that it's trying to link to the amd64 Catch2WithMain.a that is installed on my machine.
> 
> Ideally, I would like to use the arm64 version of catch2, however I don't know how to specify this in the control file. If I run sbuild with --host=arm64, it fails in the same way as above because it's trying to cross-compile but with the amd64 version of catch2. If I put catch2:arm64 in the control file sbuild tells me "catch2:arm64 [is] not installable."

Debian builds (for the archive) are always native so you don't need to
specify foreign-arch build-deps like this. You might need to qualify
build-deps by architecture if they are actually incompatible, but in
this case you just build-dep on catch2. So it's always available, even
if it's only actually used for the arm64 build.

catch.hpp is an architecture-independent file (it's just a header) and
is exactly the same for amd64 and arm64 so installing catch2:arm64 has
exactly the same effect as installing catch2:amd64 anyway. Any issues
with linking are to do with cross-compilation, not what is being
installed.

> I am clearly going about this the wrong way. I don't know how I can build an arm64 only package and ensure it only uses arm64 build dependencies. Do I need to use a VM? If I can't get this library packaged, I would have to exclude arm64 from the software I am packaging, which I really don't want to do unless absolutely necessary. Any advice would be warmly appreciated.

This is debian so we try to avoid the use of bundled stuff, as you
know. The CMAKE file has an option "OAKNUT_USE_BUNDLED_CATCH" so
making sure that is off for your build is correct.

To test the arm64 build you need to use either real arm64 hardware or
a qemu chroot. Testing the cross-build is a different thing, and
whilst it would be good to have that working too, it won't be used by
the buildds. 

I had a quick go with a trivial packaging and yes it didn't build on x86

/usr/bin/c++  -I/home/wookey/packages/oaknut/debian/oaknut-1.2.2/tests -I/home/wookey/packages/oaknut/debian/oaknut-1.2.2/include -g -O2 -ffile-prefix-map=/home/wookey/packages/oaknut/debian/oaknut-1.2.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -std=gnu++20 -Wall -Wextra -Wcast-qual -pedantic -pedantic-errors -Wfatal-errors -Wno-missing-braces -MD -MT CMakeFiles/oaknut-tests.dir/tests/vector_code_gen.cpp.o -MF CMakeFiles/oaknut-tests.dir/tests/vector_code_gen.cpp.o.d -o CMakeFiles/oaknut-tests.dir/tests/vector_code_gen.cpp.o -c /home/wookey/packages/oaknut/debian/oaknut-1.2.2/tests/vector_code_gen.cpp
/home/wookey/packages/oaknut/debian/oaknut-1.2.2/include/oaknut/feature_detection/read_id_registers_directly.hpp: Assembler messages:
/home/wookey/packages/oaknut/debian/oaknut-1.2.2/include/oaknut/feature_detection/read_id_registers_directly.hpp:15: Error: no such instruction: `mrs %r15,s3_0_c0_c0_0'
...

because indeed
include/oaknut/feature_detection/read_id_registers_directly.hpp
contains an asm section which is arm64 but not architecture gated in
any way so the scripts try to build it on x86 which is silly and won't
work. Is this library intended to only build on arm64?

I must admit to being a bit confused about the purpose of this
code. What does this code-generator do that gcc doesn't do? And why
would a complier for arm64 be written to only build on arm64?

Does the upstream _actually_ need oaknut, or would a normal assembler do? (gcc or clang or tbb etc)

If the library really does only build on arm64 then putting:
Architecture: arm64
in th control file will mean it only gets built on an arch where it will build.

In this case the package that _depends_ on oaknut will need a
conditional dependency because oaknut will only exist on arm64, not on
other arches.
The syntax is:
Build-Depends: oaknut [arm64]


Wookey
-- 
Principal hats:  Debian, Wookware, ARM
http://wookware.org/

Attachment: signature.asc
Description: PGP signature


Reply to: