Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross compiler setup - C_INCLUDE_PATH etc #609

Closed
daym opened this issue Sep 14, 2019 · 7 comments
Closed

Cross compiler setup - C_INCLUDE_PATH etc #609

daym opened this issue Sep 14, 2019 · 7 comments

Comments

@daym
Copy link
Collaborator

daym commented Sep 14, 2019

Hi,

we'd like to package Heads in the GNU Guix distribution.

There is a slight problem we are working around:

Our compilers use the (gcc) environment variables CPATH, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, LIBRARY_PATH (and OBJC_INCLUDE_PATH and OBJCPLUS_INCLUDE_PATH) in order to specify the location of the system headers, see gcc/incpath.c. Almost all our packages set those environment variables while building.

Heads builds its own cross compiler (via musl-cross) which we have already packaged.

However, when Heads later uses that cross compiler, it doesn't unset the environment variables above (it doesn't set them either--but they have been set by us before) and thus when using musl-cross's compiler we get a mix of cross and non-cross headers, which isn't good.

It would be nice if there was a generic mechanism to pass environment variables to a module. Right now, your CROSS_TOOLS make variable sometimes gets passed on as environment variable and sometimes only as (child) make variable--which isn't good.

Some of Heads' modules use the cross compiler and some use the native compiler, so it cannot be reliably automatically detected whether or not the environment variables are required--that is also why we don't just unset the environment variables before invoking make in Heads (with prebuilt musl-cross). For example the Heads module linux uses elfutils but there's no Heads module elfutils (neither cross-compiled using musl-cross nor otherwise). There are Heads modules that require both a cross and a non-cross (host) compiler.

Similar with slsh (which has a heads package) and termcap (which doesn't have a heads package - ncurses isn't used, right?).

Also, libusb seems to use CXXCPP which your main Makefile doesn't set up for the cross compiler (neither does it set up CPP).

@tlaurion
Copy link
Collaborator

Just saw this. Really interesting.

@tlaurion
Copy link
Collaborator

tlaurion commented May 4, 2020

@daym There is this PR that should resolve your issue. Please give some feeback in your use case.

@tlaurion
Copy link
Collaborator

#714 was merged.

@daym:Please update if you still have issues, please tag me in.

@daym
Copy link
Collaborator Author

daym commented May 24, 2020

@tlaurion: Thanks! It works much better now.

We had to do one more weird workaround:

  • Use elfutils 0.174 (which is older that what we usually use) for heads, because otherwise musl-cross' binutils and the newer elfutils (0.176) would not be compatible and so the build of your Linux kernel would fail. See also https://bbs.archlinux.org/viewtopic.php?id=242682

We just built heads-qemu-linuxboot successfully under Guix (with make_environment patches. I've updated the pull request #710 too).

@tlaurion
Copy link
Collaborator

@daym :
I've put your branch on my github for it to be picked up by CircleCI.
Error logs are out there if you click the "x":

make -C "/root/project/build/busybox-1.28.0" CC=/root/project/crossgcc/bin/x86_64-linux-musl-gcc -fdebug-prefix-map=/root/project=heads -gno-record-gcc-switches -D__MUSL__ -I/root/project/install/include -L/root/project/install/lib  CPP=/root/project/crossgcc/bin/x86_64-linux-musl-cpp CXXCPP=/root/project/crossgcc/bin/x86_64-linux-musl-cpp CC_FOR_BUILD= BUILD_CC= HOSTCC= AR=/root/project/crossgcc/bin/x86_64-linux-musl-ar LD=/root/project/crossgcc/bin/x86_64-linux-musl-ld STRIP=/root/project/crossgcc/bin/x86_64-linux-musl-strip NM=/root/project/crossgcc/bin/x86_64-linux-musl-nm OBJCOPY=/root/project/crossgcc/bin/x86_64-linux-musl-objcopy OBJDUMP=/root/project/crossgcc/bin/x86_64-linux-musl-objdump PKG_CONFIG_PATH=/root/project/install/lib/pkgconfig PKG_CONFIG_SYSROOT_DIR=/root/project/install    

make[1]: Entering directory '/root/project/build/busybox-1.28.0'

rm -f .kernelrelease

echo 1.28.0 > .kernelrelease

/root/project/build/busybox-1.28.0/scripts/gen_build_files.sh /root/project/build/busybox-1.28.0 /root/project/build/busybox-1.28.0

make -f scripts/Makefile.build obj=scripts/basic

   -Wp,-MD,scripts/basic/.fixdep.d         -o scripts/basic/fixdep scripts/basic/fixdep.c  

/bin/sh: 1: -Wp,-MD,scripts/basic/.fixdep.d: not found

make[2]: *** [scripts/Makefile.host:104: scripts/basic/fixdep] Error 127

make[1]: *** [Makefile:357: scripts_basic] Error 2

make[1]: Leaving directory '/root/project/build/busybox-1.28.0'

make: *** [Makefile:387: /root/project/build/busybox-1.28.0/.build] Error 1

Unfortunately, I cannot merge a build system change if it breaks the current system for another use. If you can help troubleshooting to changes can make it work for both use cases.

@daym
Copy link
Collaborator Author

daym commented May 29, 2020

@tlaurion: Sure, I understand.

I had missed the case that HOSTCC could be unset and then would be defaulted to the value gcc by busybox. As I had it it would have been set to the empty string--which is not the same as unset.

Now I also implemented support for CC_FOR_BUILD, BUILD_CC and HOSTCC unset.

@tlaurion
Copy link
Collaborator

I think this is done, where nix is used now as #1661 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants