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
cpupower, pciutils: enable cross compiling #34312
Conversation
LGTM, works for x86_64-musl, cross-x86_64-musl, aarch-64-musl and armv6l-musl! Thanks! |
While this looks perfectly reasonable to me it causes a large rebuild. Could you please change the target branch to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor fixups on cpupower.
Also, seems to have reference to build-time bash:
$ nix why-depends --all ./result/ /nix/store/0w5g7g0ddn0yqb1mjfnhdsnh0lg2mcn4-bash-4.4-p12
/nix/store/jkj7l0b0jn2z4mgavnh99qryamifxhis-cpupower-4.9.78-aarch64-unknown-linux-musl
╚═══bin/cpufreq-bench_plot.sh: …#!/nix/store/0w5g7g0ddn0yqb1mjfnhdsnh0lg2mcn4-bash-4.4-p12/bin/bash..# This p…
share/doc/cpupower/cpufreq-bench_script.sh: …#!/nix/store/0w5g7g0ddn0yqb1mjfnhdsnh0lg2mcn4-bash-4.4-p12/bin/bash..# This p…
=> /nix/store/0w5g7g0ddn0yqb1mjfnhdsnh0lg2mcn4-bash-4.4-p12
Not a big deal (script doesn't seem critical but might be good to either patch it or remove it to keep the closure neat).
|
||
stdenv.mkDerivation { | ||
name = "cpupower-${kernel.version}"; | ||
|
||
src = kernel.src; | ||
|
||
buildInputs = [ coreutils pciutils gettext ]; | ||
nativeBuildInputs = [ buildPackages.gettext ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop buildPackages.
here, just gettext
.
|
||
stdenv.mkDerivation { | ||
name = "cpupower-${kernel.version}"; | ||
|
||
src = kernel.src; | ||
|
||
buildInputs = [ coreutils pciutils gettext ]; | ||
nativeBuildInputs = [ buildPackages.gettext ]; | ||
buildInputs = [ coreutils pciutils ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coreutils
doesn't seem to be needed here? Seems to build fine when dropping it, either way output has no references to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also part of stdenv
.
buildPhase = '' | ||
make | ||
''; | ||
makeFlags = "CROSS=${stdenv.cc.targetPrefix}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makeFlags "should" be an array, I think?
@dtzWill The reference to bash is being added by patchShebangs:
It seems to me like patchShebangs doesn't do the right thing when cross compiling. |
0dca853
to
84f54b8
Compare
buildPhase = '' | ||
make | ||
''; | ||
makeFlags = [ "CROSS=${stdenv.cc.targetPrefix}" ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be stdenv.hostPlatform.config
, right? (The practical difference is the trailing -
, the conceptual difference is what I wrote identifies the platform, whereas that is just the disambiguating prefix of the compiler and need not be anything in particular.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of CROSS
is used as the compiler and linker prefix in the Makefile (see here), so isn't targetPrefix
the right value for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sounds good
@@ -11,7 +11,7 @@ stdenv.mkDerivation rec { | |||
nativeBuildInputs = [ pkgconfig ]; | |||
buildInputs = [ zlib kmod which ]; | |||
|
|||
makeFlags = "SHARED=yes PREFIX=\${out}"; | |||
makeFlags = [ "SHARED=yes" "PREFIX=\${out}" "STRIP=" "HOST=${stdenv.hostPlatform.system}" "CROSS_COMPILE=${stdenv.cc.targetPrefix}" ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh I don't think this alone is enough? @dtzWill and I ran into problems before with make
running ./lib/Configure
without any arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of problems? It builds fine for me and @dtzWill tested it as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we tried fewer arguments there; maybe these are sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last thing, normally HOST=${stdenv.hostPlatform.config}
would be better. Are you sure the shorter nix-style names are superior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HOST
variable is parsed using custom code in the configure script (see here), so it does not follow a standard format (such as the LLVM target triple). When it is not manually specified, it is pieced together from uname -s
, uname -r
and a number of other commands depending on the OS. It just so happens that it matches the value of stdenv.hostPlatform.config
for most systems. The only exception I can see is that when stdenv.hostPlatform.config == "i686-linux"
, the value of HOST
should be i386-linux
(see line 28), so this may break i686 builds, but I don't have a way to test this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks for the diligent research! If you put that in a comment, this is fine with me. We just need a patchShebangs solution then?
Regarding patchShebangs, cc #33956. |
I'm not sure we need to block this on fixing the patchShebangs situation, since that is a problem in many packages. |
Oh ok. |
Motivation for this change
This PR fixes cross compiling for cpupower and pciutils (a dependency of cpupower).
Things done
This PR uses some different flags for pciutils than the commit that was dropped from #34173. Of particular importance is the
HOST
variable, which has to be set correctly for aarch64 cross compiling to work. Coincidentally, the format of this variable is the same as the value ofstdenv.hostPlatform.system
for most architectures and operating systems, (Linux, Darwin, x86_64, aarch64 and armv7l, although it looks like the cpu name should be i386 for i686).I have tested these changes natively on x86_64 and aarch64, as well as cross compiling for armv7l and aarch64.
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)