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

Make cross compilation elegant #26805

Merged
merged 21 commits into from
Dec 31, 2017
Merged

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jun 24, 2017

Motivation for this change

#26881 has the easy cleanups of individual derivations, but there is some more complex cleanups to core infrastructure that should also be made. This PR is for them.

Because these changes are both complex, and cause huge mass rebuilds, it will take longer to get right. I might or might not might land #26799 or #25047 in the meantime, for example. Opening now because such changes warrant much discussion.

When #26881 is merged, I'll repoint those hydra jobs at this.

Things done

@periklis I opened https://github.com/NixOS/nixpkgs/projects/8 as a meta-issue; also see these new TODOs below.

  • Build stdenv
    • Linux
    • Darwin
  • Break up big WIP commit at the end into more readable chunks---perhaps such per-package changes can be merged separately before this PR too. If this is done carefully, the final tree hash will stay the same and we won't mass-rebuild ourselves.
  • Make @globin's doc fixes---see review below.
  • Rewrite documentation to reflect the sorts of dependencies I added, and their new names.
  • optional, will still be an improvement Pass much of cross test suite (besides including MinGW) http://hydra.nixos.org/jobset/nixpkgs/ericson2314-cross-trunk
  • Put (propagated)buildInputs back on the PATH when not cross-compiling, to lessen potential breakage.---but I want to make sure at least the stdenv builds before I do this.
  • Don't prune native of native, to lessen potential breakage. Breakage dealt with despite this
  • Prevent regressions
  • Fix Qt derivations based on what @ttuegel said.
  • Clean up propagation description in documentation
  • Track down any more unwanted __ (some in docs, it seems)
  • Add release notes for NixOS

CC @Dridus @matthewbauer @DavidEGrayson @bgamari

];

makeFlags = [
"PREFIX=${stdenv.cross.config}-"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be PREFIX=${hostPlatform.config}-? (Or at least not stdenv.cross ...?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

@@ -80,11 +80,11 @@ stdenv.mkDerivation rec {

# Works around a bug with 8.26:
# Makefile:3440: *** Recursive variable 'INSTALL' references itself (eventually). Stop.
${if hostPlatform == buildPlatform then null else "preInstall"} = ''
preInstall = optionalString (hostPlatform == buildPlatform) ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Inverted logic? Isn't it so that when you're building for host != build, then you'd like to use "install" from the buildPackages set?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed!

sed -i Makefile -e 's|^INSTALL =.*|INSTALL = ${buildPackages.coreutils}/bin/install -c|'
'';

${if hostPlatform == buildPlatform then null else "postInstall"} = ''
postInstall = optionalString (hostPlatform == buildPlatform) ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Same inverted logic?

# Formally:
#
# propagated-dep(m, A, B)
# propagated-dep(m, B, C)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should one of these "m"s be "n"?

Copy link
Member Author

Choose a reason for hiding this comment

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

hehe, too much copy paste

@bjornfor
Copy link
Contributor

The commit message in "stdenv: Fix handling of dependencies and hooks" says

  • "... crops up more that one might think it old commonly used C libraries". I think you mean "in", not "it".
  • "... pick up any libraries for it's target platform". it's -> its.

I think it'd be nice if the documentation in the commit message was added to "pkgs/stdenv/generic/setup.sh".

@bjornfor
Copy link
Contributor

I have nothing to say about the code other than the nitpicks above. Looks good to me!

I'm always happy to see you work on cross-compilation :-)

@@ -15,13 +14,6 @@ stdenv.mkDerivation rec {

nativeBuildInputs = [ lzip ];

doCheck = hostPlatform == buildPlatform;

${if hostPlatform != buildPlatform then "crossPlatforms" else null} = [ ];
Copy link
Member Author

Choose a reason for hiding this comment

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

This should have been configurePlatforms, but that wasn't shows that isn't needed after all!

@@ -23,13 +22,13 @@ stdenv.mkDerivation {
./CVE-2015-7697.diff
./CVE-2014-9913.patch
./CVE-2016-9844.patch
./cross-cc.patch;
Copy link
Member

Choose a reason for hiding this comment

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

this does not look right.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually it is. I changed makefile to only define the c compiler as a fallback: CC ?= cc. What I can do is give the patch a better name :)

Copy link
Member

@Mic92 Mic92 Jun 26, 2017

Choose a reason for hiding this comment

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

What I meant the trailing semicolon might be unintended, isn't it?

@Ericson2314
Copy link
Member Author

OK renamed patches and overhauled documentation.

@Ericson2314 Ericson2314 force-pushed the cross-elegant branch 3 times, most recently from ba655a4 to b80754c Compare June 26, 2017 06:03
@Ericson2314
Copy link
Member Author

Cleaned up cc-wrapper, and made misc packages use preNativeBuildInputs too.

The stdenv commit unfortunately causes some infinite reversion. No idea why; if anyone could figure out that would be much appreciated.

@copumpkin
Copy link
Member

copumpkin commented Jun 26, 2017

It really makes it pretty hard to review or follow things like this when every change on this topic is a batch of commits with a total of several hundred lines of changes, often later getting closed with "I redid all this work in PR 12345". Like you saying, "hey the third commit of six has an obscure bug I haven't been able to figure out; please help!" might be a hint that you're lumping too much together. Especially when that problematic commit then has a commit message starting with "3 big changes: ". It's just daunting to me, and I doubt I'm alone.

Don't get me wrong: I appreciate all the work you're putting in here, and appreciate descriptive commit messages, but I think this tweet sums up my position on code reviews. Too small and they tend to be nitpicky, but too big and there's just too much going on for anyone to get enough context to provide a meaningful review without investing an hour or more into it, which is more than most people are willing to put in. If your goal as a code author is to get meaningful feedback from other people with relevant expertise, I'd urge you to not only optimize your code for correctness (which you're probably fine with) but optimize your coding practice to enable the rest of us to see that it's correct. That'll mean smaller, more focused commits, more focused PRs, even if that sometimes means not writing a feature the way it comes naturally to you, in order to make it more incremental and consumable by the rest of us.

Anyway, that's just my two cents. Please don't take it as anything more than what I'm saying. I really want your stuff to land and generally love and appreciate all the cross-compilation revamp and cleanup work you've been doing, but I fairly consistently can make very little sense of your PRs. That might just be me, of course 😄

@copumpkin
Copy link
Member

Okay, I take some of that back, sorry. After looking more carefully at the stdenv commit in question, I now see that most of the changes are documentation changes, which I really appreciate, and the remainder is fairly small logic. I just knee-jerked too hard at the "3 big changes" in the commit message. Anyway, given that, I don't know if there's much remaining truth to my original point but I'll leave it up and see what you think.

`dontStrip` is still a catch-all, but `dontStripHost` and
`dontStripTarget` are also now available for finer-grained disabling.
This commits needs a MAJOR audit as I oftentimes just guessed which of
`$hostOffset`, `$targetOffset`, or a fixed offset should be used.
 - All deps go on the PATH

 - CC and Bintools wrappers with their host != depender's host still get their
   setup hooks run.

 - Environment hooks get applied to all packages

This isn't so elegent, but eases the transition on a very significant
PR.
It was improperly classified a build-time dep to get around the
incorrect propagation logic that was in place before this PR.

Additionally fix some `kdoctools` usage were it is incorrectly used a
run-time dep.
@Ericson2314
Copy link
Member Author

Ericson2314 commented Dec 31, 2017

@bgamari Thanks for your very thoughtful and thorough review!

I fixed everything I could (including start cookbook with your examples) that wouldn't cause a mass rebuild (e.g. more comments in pkgs/generic/setup.sh). Those I'll make after and merge as we work through #30882. That way the last few stalled-looking jobs finish OK (We can already see how they turned out before, but just to double check.)

I'll be around a lil bit tomorrow to help put out any fires (e.g. some rustc on Darwin) that may arise.

Code-churn wise, this cross saga is all downhill from hill. :)

This accounts for all the new dependencies and propagation logic changes
I'm about to add.

Fixes NixOS#1915---with this change I think the distinction is finally clear
enough.
@Ericson2314 Ericson2314 merged commit 4d2b763 into NixOS:staging Dec 31, 2017
@Ericson2314 Ericson2314 deleted the cross-elegant branch December 31, 2017 03:59
@CMCDragonkai
Copy link
Member

Wow this is merged now! Congrats!


# Ensure we're in bounds relative to the package currently
# being built.
[[ "${allPlatOffsets[*]}" = *"$hostOffsetNext"* ]] || continue
Copy link
Contributor

Choose a reason for hiding this comment

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

This naïve substring match considers 1 to be a substring of -1. Did you mean to write this?

-         [[ "${allPlatOffsets[*]}" = *"$hostOffsetNext"*  ]] || continue
+         [[ " ${allPlatOffsets[*]} " = *" $hostOffsetNext "* ]] || continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Cross compilation
@Ericson2314's Big PR
Development

Successfully merging this pull request may close these issues.

None yet