Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Allow cross compiling #150

Merged
merged 1 commit into from
Apr 2, 2021
Merged

Allow cross compiling #150

merged 1 commit into from
Apr 2, 2021

Conversation

jesec
Copy link
Contributor

@jesec jesec commented Apr 1, 2021

To test on Ubuntu (amd64 host):

# Install toolchain
$ sudo apt install build-essential gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu

# Set ENV for cross toolchain
$ export CC=/usr/bin/aarch64-linux-gnu-gcc CXX=/usr/bin/aarch64-linux-gnu-g++ AR=/usr/bin/aarch64-linux-gnu-ar NM=/usr/bin/aarch64-linux-gnu-nm READELF=/usr/bin/aarch64-linux-gnu-readelf

# Set ENV for host toolchain
$ export CC_host=/usr/bin/gcc CXX_host=/usr/bin/g++ AR_host=/usr/bin/ar NM_host=/usr/bin/nm READELF_host=/usr/bin/readelf

# Run pkg-fetch
$ pkg-fetch --force-build --arch arm64

Copy link
Contributor

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robertsLando
Copy link
Contributor

Would add some docs about this btw like the example mentioned here

@@ -108,6 +108,12 @@ async function compileOnUnix(nodeVersion: string, targetArch: string) {
args.push('--dest-cpu', cpu);
}

if (hostArch !== targetArch) {
log.warn('Cross compiling!');
log.warn('You are responsible for appropriate env like CC, CC_host, etc.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should link out to more information. What is CC, CC_host? Where can I learn more?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there is no documentation there. Even Node.js does not provide one on the topic of cross-compilation.

CC is "C Compiler".
CC_host is "C Compiler for the host".

Users are kinda expected to know this, if they wish to take advantage of this more advanced option. Of course, I am always open to better docs, but I don't think I can do a "cross compile 101" here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead of making it working by default and show a warning would be better to force the flag to be there, if it is not there throw like it was before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would fail (very soon). So there is no need for that. That would also drastically increase the complexity of matrix-based CI workflows, as we probably don't want the flag when compile natively.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok LGTM for me so

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the documentation to the README then, and then link to the readme in the error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and, FYI: upstream (Node.js) builds and tests natively. See https://github.com/nodejs/build . They have native machines donated by IBM, ARM, etc. That explains why there is very little documentation on cross compilation.

There is no guaranteed good documentation here. Cross compilation is quite complicated. For instance, GCC vs LLVM: GCC uses separate binaries but LLVM uses --target=<triple> and other flags. And, the instructions for how to install a cross toolchain obviously vary a lot between distros.

I think it would be challenging to add any documentation, and we should probably follow the example of upstream, and ask advanced users to explore the codes, workflows and Google for answers instead.

@jesec
Copy link
Contributor Author

jesec commented Apr 2, 2021

I am merging this for now, so we can start to make binaries. It works here (my local machine, Ubuntu, for arm64) and there (https://github.com/jesec/pkg-fetch/actions/runs/710314809, Windows, for arm64).

I am of course always open to better docs and we should do that in a later change.

@jesec jesec merged commit d7f7490 into master Apr 2, 2021
@jesec jesec deleted the pr/cross-compile branch April 2, 2021 11:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants