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

chromium: cross compilation support #229265

Merged
merged 6 commits into from Aug 4, 2023
Merged

chromium: cross compilation support #229265

merged 6 commits into from Aug 4, 2023

Conversation

ghost
Copy link

@ghost ghost commented May 1, 2023

Description of changes

This commit successfully cross-compiles chromium from buildPlatform=x86_64-linux to hostPlatform=aarch64-linux.

Other PRs included in this one (can be reviewed/merged independently):

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux (cross from x86_64-linux)
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label May 1, 2023
@ghost ghost requested a review from Artturin May 1, 2023 11:36
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels May 1, 2023
@ghost ghost marked this pull request as ready for review May 1, 2023 12:52
@Artturin
Copy link
Member

Artturin commented May 1, 2023

separated chromium: set TERM=dumb for ninja & chromium: do not skip {pre,post}Build #229367

@ghost
Copy link
Author

ghost commented May 1, 2023

$ nix-instantiate . -A pkgsCross.aarch64-multiplatform.ungoogled-chromium
/nix/store/va4rvfk8i5q7pgl9g7l0wph9s5aj3lfc-ungoogled-chromium-aarch64-unknown-linux-gnu-112.0.5615.165.drv
$ nix-build /nix/store/va4rvfk8i5q7pgl9g7l0wph9s5aj3lfc-ungoogled-chromium-aarch64-unknown-linux-gnu-112.0.5615.165.drv
/nix/store/w2waiscdk40d07cd3f5x0hjca32j65gz-ungoogled-chromium-aarch64-unknown-linux-gnu-112.0.5615.165

@ofborg build pkgsCross.aarch64-multiplatform.ungoogled-chromium

Adam Joseph added 6 commits July 5, 2023 03:32
xdg-utils does not cross-compile.  Let's late-bind (using the
runtime $PATH) in this scenario so a native-built xdg-utils can be
used instead.
`llvmPackages.clang` is used in the `gnFlags` attrset, so we need to
indicate explicitly which "on" platform (the build) and which "for"
platform (the host) we want.  This commit does that.
ungoogled-chromium is, contrary to its name, not a build of
chromium.  It is a patched copy of chromium's *source
code*. Therefore, it needs to come from pkgsBuildBuild, because it
contains python scripts which get /nix/store/.../bin/python3 patched
into their shebangs.
Sometimes we access `llvmPackages` via `pkgs`, and other times via
`pkgsFooBar`, so unfortunately a string (attrname) is the only way
to have a single point of control over the LLVM version used for
both buildPlatform and hostPlatform.
This commit successfully cross-compiles chromium from
buildPlatform=x86_64-linux to hostPlatform=aarch64-linux.

Other PRs in this project (can be reviewed/merged independently of
this one):

- #227707
- #227708
- #227710
- #227719
- #227720
- #227722
- #227723
@ghost
Copy link
Author

ghost commented Jul 12, 2023

Rebased.

Copy link
Member

@michaeladler michaeladler left a comment

Choose a reason for hiding this comment

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

Looks like quite the ordeal. Nice job! If it builds, then it's fine with me :)

pkgsBuildBuild.pkg-config
libuuid
libpng # `.override` used below does not splice
] ++ buildInputs;
Copy link
Member

Choose a reason for hiding this comment

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

That's weird, Why is it necessary

Copy link
Author

Choose a reason for hiding this comment

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

After investigating more closely I think the comment is incorrect.

I think pkgsBuildBuild.libpng is needed for something Chromium is doing at build time, not because of anything related to splicing. I'm verifying this and will remove the comment (or the entire line) once I do.

Copy link
Member

Choose a reason for hiding this comment

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

I'm saying ++ buildInputs is weird

Copy link
Author

Choose a reason for hiding this comment

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

Chromium compiles a ton of stuff for both the hostPlatform and the buildPlatform (which, confusingly, it calls "host"... argh). For example, in order to dump out a "quick-start image" for the javascript VM it builds an entire buildPlatform version of it!

I could slog through every last dependency and figure out exactly which ones are/aren't needed on the host, but then that list would need to be maintained separately. It's definitely more than half of them.

Copy link
Author

Choose a reason for hiding this comment

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

See ea7c3166548919ba63c204f47598e8522de1c2d3

@ofborg ofborg bot requested a review from michaeladler July 14, 2023 06:04
@ghost ghost requested a review from lorenz July 18, 2023 20:28
@ghost
Copy link
Author

ghost commented Jul 18, 2023

Rebased.

@ghost ghost mentioned this pull request Jul 18, 2023
12 tasks
@Artturin
Copy link
Member

Artturin commented Aug 3, 2023

Very messy but I guess that's just how browsers are...

@Artturin
Copy link
Member

Artturin commented Aug 3, 2023

Merge after someone confirms that there's no build time deps included in the cross closure
nix path-info -rsh ./result | rg --invert-match "aarch"

@Artturin
Copy link
Member

Artturin commented Aug 4, 2023

There's no for build deps in the output

It took 3 hours to build chromium...

@Artturin Artturin merged commit 4055d18 into NixOS:master Aug 4, 2023
@ghost ghost deleted the pr/chromium/cross/all branch August 5, 2023 05:32
@ghost
Copy link
Author

ghost commented Aug 5, 2023

There's no for build deps in the output

Should I add a disallowedReferences to ensure that none leak into the output in the future?

@Artturin
Copy link
Member

Artturin commented Aug 5, 2023

There's no for build deps in the output

Should I add a disallowedReferences to ensure that none leak into the output in the future?

Sure, check how I did it in systemd.

@emilylange
Copy link
Member

emilylange commented Oct 19, 2023

This increased the build steps and build time for non cross-compilation (e.g. chromium.browser) by a lot.
We are talking ~54000 vs ~85000 (and lately ~95000, showing a trend that suggests it gets even worse with each release).

It almost feels like we are building certain things twice.

Would you mind looking into this again @amjoseph-nixpkgs?

Edit: Wait. Are we cross-compiling to the same architecture if not invoked by pkgsCross?

Comment on lines +328 to +330
target_cpu = chromiumRosettaStone.cpu stdenv.hostPlatform;
v8_target_cpu = chromiumRosettaStone.cpu stdenv.hostPlatform;
target_os = chromiumRosettaStone.os stdenv.hostPlatform;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

@ghost
Copy link
Author

ghost commented Oct 30, 2023

Edit: Wait. Are we cross-compiling to the same architecture if not invoked by pkgsCross?

Chromium has its own totally custom build system, and it's a gigantic pain in the ass. That's why chromium (and &(^&% QT) were among the very last parts of nixpkgs to support cross-compiling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cross-compilation Building packages on a different platform than they will be used on 8.has: clean-up 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 11-100
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants