Cross-compiling with mach

Discussions about the development and maturation of the platform code (UXP).
Warning: may contain highly-technical topics.

Moderators: trava90, athenian200

User avatar
PseudoDistant
Moonbather
Moonbather
Posts: 73
Joined: 2024-02-06, 20:19

Cross-compiling with mach

Unread post by PseudoDistant » 2024-03-15, 15:29

So I've been away for a bit, had to deal with something else.

Anyway, I'm trying to compile UXP for aarch64. I've run into this wall here.

Code: Select all

 0:01.19 ERROR: Target C compiler target CPU (x86_64) does not match --target CPU (aarch64)
 0:01.20 *** Fix above errors and then restart with\
 0:01.20                "/usr/bin/make -f client.mk build"
 0:01.20 make: *** [client.mk:370: configure] Error 1
Does Mach not support cross-compiling, or is there something wrong with my setup?

OS: Arch Linux x86_64
Kernel: 6.7.9-zen1-1-zen
CPU: AMD Ryzen 5 5600X3D (12) @ 3.300GHz

.mozconfig

Code: Select all

_BUILD_64=1

ac_add_options --enable-application=palefox
ac_add_options --target=aarch64-linux-android
ac_add_options --with-android-sdk="/home/distant/Android/Sdk"
ac_add_options --enable-optimize="-O2 -w"
ac_add_options --enable-jemalloc
ac_add_options --enable-strip
ac_add_options --enable-devtools
ac_add_options --disable-gamepad
ac_add_options --disable-tests
ac_add_options --disable-debug
ac_add_options --disable-necko-wifi
ac_add_options --disable-updater
ac_add_options --with-pthreads

ac_add_options --enable-phoenix-extensions

# Processor architecture specific build options
if [ -n "$_BUILD_64" ]; then
  ac_add_options --x-libraries=/usr/lib64
else
  ac_add_options --x-libraries=/usr/lib
fi
Eat your school.
Eat your drugs.
Eat your teeth.

User avatar
athenian200
Contributing developer
Contributing developer
Posts: 1537
Joined: 2018-10-28, 19:56
Location: Georgia

Re: Cross-compiling with mach

Unread post by athenian200 » 2024-03-15, 15:55

Well, the thing about cross-compiling is that you can't just use the same compiler you would normally use. You need a GCC specifically compiled for that, and a way of pointing to that version of GCC. From my understanding of the error message, you are trying to cross-compile using the normal GCC that's designed to put out x86_64 object code, and that's never going to work.

What you would need to do is compile or install a version of GCC that runs on x86_64 and produces aarch64 object code, and then on top of that, you need to add a line to your .mozconfig like:

Code: Select all

export CC="aarch64-linux-gnu-gcc"

Or whatever your distro calls the aarch64 cross-compiler if they provide one. That is to say, normal gcc won't just generate aarch64 object code, only a second installation of gcc that targets the other architecture can do that.
"The Athenians, however, represent the unity of these opposites; in them, mind or spirit has emerged from the Theban subjectivity without losing itself in the Spartan objectivity of ethical life. With the Athenians, the rights of the State and of the individual found as perfect a union as was possible at all at the level of the Greek spirit." -- Hegel's philosophy of Mind

User avatar
PseudoDistant
Moonbather
Moonbather
Posts: 73
Joined: 2024-02-06, 20:19

Re: Cross-compiling with mach

Unread post by PseudoDistant » 2024-03-15, 16:22

athenian200 wrote:
2024-03-15, 15:55
Well, the thing about cross-compiling is that you can't just use the same compiler you would normally use. You need a GCC specifically compiled for that, and a way of pointing to that version of GCC. From my understanding of the error message, you are trying to cross-compile using the normal GCC that's designed to put out x86_64 object code, and that's never going to work.

What you would need to do is compile or install a version of GCC that runs on x86_64 and produces aarch64 object code, and then on top of that, you need to add a line to your .mozconfig like:

Code: Select all

export CC="aarch64-linux-gnu-gcc"

Or whatever your distro calls the aarch64 cross-compiler if they provide one. That is to say, normal gcc won't just generate aarch64 object code, only a second installation of gcc that targets the other architecture can do that.
I see. I have the gcc aarch64 already, other build tools I've used automatically swap to the one appropriate for the output.
I didn't understand that mach didn't do this, thank you.
Eat your school.
Eat your drugs.
Eat your teeth.

User avatar
PseudoDistant
Moonbather
Moonbather
Posts: 73
Joined: 2024-02-06, 20:19

Re: Cross-compiling with mach

Unread post by PseudoDistant » 2024-03-15, 16:28

Code: Select all

 0:00.52 checking for the target C compiler... /usr/bin/aarch64-linux-gnu-gcc
 0:00.54 checking whether the target C compiler can be used... yes
 0:00.55 checking for git... /usr/bin/git
 0:00.55 checking for Git version... 2.44.0.248.g4f9b731bdec
 0:00.55 checking for pkg_config... /usr/bin/pkg-config
 0:00.55 checking for pkg-config version... 2.1.0
 0:00.55 checking for yasm... /usr/bin/yasm
 0:00.56 checking yasm version... 1.3.0
 0:00.56 checking for nasm... /usr/bin/nasm
 0:00.56 checking nasm version... 2.16.01
 0:00.56 checking for android ndk version... 21.0.6113669
 0:00.56 checking for android platform directory... /home/distant/Android/Sdk/ndk/21.0.6113669/platforms/android-21/arch-arm64
 0:00.56 checking the target C compiler version... 13.2.0
 0:00.58 checking the target C compiler works... yes
 0:00.58 checking for the target C++ compiler... /usr/bin/aarch64-linux-gnu-g++
 0:00.59 checking whether the target C++ compiler can be used... yes
 0:00.59 checking the target C++ compiler version... 13.2.0
 0:00.61 checking the target C++ compiler works... yes
 0:00.61 checking for the host C compiler... /usr/bin/gcc
 0:00.62 checking whether the host C compiler can be used... no
 0:00.62 DEBUG: <truncated - see config.log for full output>
 0:00.62 DEBUG: | %KERNEL "Linux"
 0:00.62 DEBUG: | #elif _WIN32 || __CYGWIN__
 0:00.62 DEBUG: | %KERNEL "WINNT"
 0:00.62 DEBUG: | #elif __NetBSD__
 0:00.62 DEBUG: | %KERNEL "NetBSD"
 0:00.62 DEBUG: | #elif __APPLE__
 0:00.63 DEBUG: | %KERNEL "Darwin"
 0:00.63 DEBUG: | #endif
 0:00.63 DEBUG: | #if _MSC_VER || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 0:00.63 DEBUG: | %ENDIANNESS "little"
 0:00.63 DEBUG: | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 0:00.63 DEBUG: | %ENDIANNESS "big"
 0:00.63 DEBUG: | #endif
 0:00.63 DEBUG: Executing: `/usr/bin/gcc -std=gnu99 -E /tmp/conftest._3h_eR.c`
 0:00.63 DEBUG: COMPILER = gcc
 0:00.63 DEBUG: VERSION = 13.2.1
 0:00.63 DEBUG: STDC_VERSION = 199901L
 0:00.63 DEBUG: CPU = x86_64
 0:00.63 DEBUG: KERNEL = Linux
 0:00.63 DEBUG: ENDIANNESS = little
 0:00.63 ERROR: Host C compiler target CPU (x86_64) does not match --host CPU (aarch64)
 0:00.64 *** Fix above errors and then restart with\
 0:00.64                "/usr/bin/make -f client.mk build"
 0:00.64 make: *** [client.mk:149: configure] Error 1
It seems to revert to the "host C compiler" later, even with the export.. :wtf:
Eat your school.
Eat your drugs.
Eat your teeth.

User avatar
andyprough
Keeps coming back
Keeps coming back
Posts: 752
Joined: 2020-05-31, 04:33

Re: Cross-compiling with mach

Unread post by andyprough » 2024-03-15, 16:56

Is experimental --enable-bootstrap in .mozconfig available for Pale Moon per https://firefox-source-docs.mozilla.org ... mpile.html

Or is that just for more recent versions of Firefox?

User avatar
PseudoDistant
Moonbather
Moonbather
Posts: 73
Joined: 2024-02-06, 20:19

Re: Cross-compiling with mach

Unread post by PseudoDistant » 2024-03-15, 17:13

andyprough wrote:
2024-03-15, 16:56
Is experimental --enable-bootstrap in .mozconfig available for Pale Moon per https://firefox-source-docs.mozilla.org ... mpile.html

Or is that just for more recent versions of Firefox?

Code: Select all

 0:00.54 mozbuild.configure.options.InvalidOptionError: Unknown option: --enable-bootstrap
Eat your school.
Eat your drugs.
Eat your teeth.

User avatar
andyprough
Keeps coming back
Keeps coming back
Posts: 752
Joined: 2020-05-31, 04:33

Re: Cross-compiling with mach

Unread post by andyprough » 2024-03-15, 17:20

PseudoDistant wrote:
2024-03-15, 17:13

Code: Select all

 0:00.54 mozbuild.configure.options.InvalidOptionError: Unknown option: --enable-bootstrap
Guess not.

User avatar
athenian200
Contributing developer
Contributing developer
Posts: 1537
Joined: 2018-10-28, 19:56
Location: Georgia

Re: Cross-compiling with mach

Unread post by athenian200 » 2024-03-15, 22:15

PseudoDistant wrote:
2024-03-15, 16:28
It seems to revert to the "host C compiler" later, even with the export.. :wtf:
Not quite! There's a slight difference in the error message you get the second time.

Earlier, you were getting this one:
0:01.19 ERROR: Target C compiler target CPU (x86_64) does not match --target CPU (aarch64)
Now you're getting this:

0:00.63 ERROR: Host C compiler target CPU (x86_64) does not match --host CPU (aarch64)

It's worth noting that I remember reading somewhere that Mozilla has their build system's definition of host and target backwards, so it's possible that they don't mean what they should mean, and you may have to set both explicitly in the right way. The older build documentation I saw years ago talked about the cross-compile process, but they've since dumbed it down and now only offer the way to do it on modern Mozilla, with their infrastructure. :/

The thing is, you're setting --target in your .mozconfig, but there's also a --host option... you may need to play around with that one to get a working configuration.

I just happen to know that these options work because I accidentally stumbled onto them while trying to port Pale Moon to SunOS... I had to explicitly set both --host and --target to x86_64, in order to override the compiler defaulting to 32-bit x86. That's how I know the plumbing for cross-compiling is still in there at least somewhat, though I've never really used it the way you're trying to.
"The Athenians, however, represent the unity of these opposites; in them, mind or spirit has emerged from the Theban subjectivity without losing itself in the Spartan objectivity of ethical life. With the Athenians, the rights of the State and of the individual found as perfect a union as was possible at all at the level of the Greek spirit." -- Hegel's philosophy of Mind

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2195
Joined: 2018-05-05, 13:29

Re: Cross-compiling with mach

Unread post by vannilla » 2024-03-16, 00:29

athenian200 wrote:
2024-03-15, 22:15
It's worth noting that I remember reading somewhere that Mozilla has their build system's definition of host and target backwards, so it's possible that they don't mean what they should mean, and you may have to set both explicitly in the right way.
Having somewhat delved into the internals of mach (or rather, its commands), I believe that is Autoconf 2.13, not Mozilla in itself. In fact, the versions after 2.13 state in their documentation that --host and --target (and a few other related options) now work "as intended".