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 compilation fixes [april 2020] #84415

Merged
merged 33 commits into from Apr 13, 2020

Conversation

matthewbauer
Copy link
Member

More cross-compilation fixes.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

- Need custom pkg-config setting
- add wayland & libxkbcommon
@ofborg ofborg bot added 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: nixos 8.has: module (update) labels Apr 6, 2020
@doronbehar
Copy link
Contributor

@matthewbauer I just came about #83575 which suggests that dvtm should have ncurses in it's native build inputs (or alike). Is there a chance you could take a look at that and perhaps fix it in this PR as well? Thanks.

# libvpx darwin targets include darwin version (ie. ARCH-darwinXX-gcc, XX being the darwin version)
# See all_platforms: https://github.com/webmproject/libvpx/blob/master/configure
# Darwin versions: 10.4=8, 10.5=9, 10.6=10, 10.7=11, 10.8=12, 10.9=13, 10.10=14
"--force-target=${stdenv.hostPlatform.config}${
"--force-target=${stdenv.hostPlatform.parsed.cpu.name}-${stdenv.hostPlatform.parsed.kernel.name}${
Copy link
Member

Choose a reason for hiding this comment

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

Nice. I strugged with this one. I think so on aarch64 it is still incorrect because arm64 != aarch64.

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -88,7 +90,7 @@ stdenv.mkDerivation {

makeFlags = [
"prefix=\${out}"
"SHELL_PATH=${stdenv.shell}"
"SHELL_PATH=${if (stdenv.hostPlatform != stdenv.buildPlatform) then "/bin/sh" else stdenv.shell}"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"SHELL_PATH=${if (stdenv.hostPlatform != stdenv.buildPlatform) then "/bin/sh" else stdenv.shell}"
"SHELL_PATH=${runtimeShell}"

Copy link
Member

Choose a reason for hiding this comment

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

Just read the commit message... The only pure alternative to your approach would be to replace stdenv.shell with runtimeShell in $out.

Copy link
Member

Choose a reason for hiding this comment

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

Otherwise if we have a sandbox build /bin/sh is reasonable reproducible, could add the reasoning as a comment above for a future reader?

Copy link
Member

Choose a reason for hiding this comment

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

We are referencing "/bin/sh" in nixpkgs … oh no.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah if it is about the old vs new version of the code (stateful) I like to put in the commit message, but if it is about the new version of the code alone, I rather it be a comment.

Comments have a prayer of being edited to stay up to date :), but commit messages only describe a moment in time.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah - patch-shebangs.sh bails out when the path is in the nix store.

I'll leave this change out of this set for now. Using /bin/sh is definitely not good, so some other fix is needed. Git will still build, you just can't run some of its shell scripts.

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 isn't this a general problem with cross builds, for e.g. Python install scripts?

How about using a substitution set for buildDeps that should be replaced with runDeps? And maybe automatically testing for buildDeps that are referenced in the output but not specifically allowed?

[target."${toRustTarget stdenv.hostPlatform}"]
"linker" = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"
EOF
'';
Copy link
Member

Choose a reason for hiding this comment

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

Can we share this with the other places we do this?

Copy link
Member

Choose a reason for hiding this comment

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

Some setup hook would be nice if it is not possible to hard code this during compilation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah a better solution would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm actually going to leave this out of this batch of cross fixes since there are a lot of questions on this (like why can't we do vala / gtk-doc / gobject-introspection when cross-compiling). These commits still exist on my other branch though:

https://github.com/matthewbauer/nixpkgs/tree/kiosk3

- add glib to nativeBuildInputs
- only update loaders cache on native builds
This is needed in cross where systemd is not in path.
Also set wayland-scanner to proper path
These should be runtime, not build time deps
Unfortunately, we need to emulate the system to get a real cache.
Native version doesn’t know the right paths.
We can’t cross-compile the cache, so just skip it for now.
This prevents duplication in cross-compiled nixos machines. The
bootstrapped glibc differs from the natively compiled one, so we get
two glibc’s in the closure. To reduce closure size, just use
stdenv.cc.libc where available.
fixes cross compilation
This fixes an evaluation error that occurs when we don’t have
bluez.test. getOutput defaults to "out" in these cases.
@matthewbauer matthewbauer changed the base branch from master to staging April 6, 2020 20:38
@matthewbauer matthewbauer changed the base branch from staging to master April 13, 2020 20:47
@matthewbauer matthewbauer changed the base branch from master to staging April 13, 2020 20:47
@matthewbauer matthewbauer merged commit e520d6a into NixOS:staging Apr 13, 2020
impl added a commit to impl/nixpkgs that referenced this pull request Sep 12, 2021
In NixOS#84415, autoPatchelfHook was taught to use the correct path to the
readelf binary when a crossSystem is specified. Unfortunately, the
remainder of the functionality in the script depended on ldd, which only
reads ELF files of its own architecture. It has the further unfortunate
quality of not reporting any useful error, but rather that the file is
not a dynamic executable.

This change uses patchelf to directly analyze the DT_NEEDED tags in the
target files instead, which correctly works across architectures. It
also updates the use of objdump to be prefix-aware $OBJDUMP (which would
have been required in the PR mentioned above, but we never made it that
far into the script execution).
bjornfor pushed a commit to bjornfor/nixpkgs that referenced this pull request Jun 7, 2022
In NixOS#84415, autoPatchelfHook was taught to use the correct path to the
readelf binary when a crossSystem is specified. Unfortunately, the
remainder of the functionality in the script depended on ldd, which only
reads ELF files of its own architecture. It has the further unfortunate
quality of not reporting any useful error, but rather that the file is
not a dynamic executable.

This change uses patchelf to directly analyze the DT_NEEDED tags in the
target files instead, which correctly works across architectures. It
also updates the use of objdump to be prefix-aware $OBJDUMP (which would
have been required in the PR mentioned above, but we never made it that
far into the script execution).

(cherry picked from commit b79483d)
bjornfor pushed a commit that referenced this pull request Jun 12, 2022
In #84415, autoPatchelfHook was taught to use the correct path to the
readelf binary when a crossSystem is specified. Unfortunately, the
remainder of the functionality in the script depended on ldd, which only
reads ELF files of its own architecture. It has the further unfortunate
quality of not reporting any useful error, but rather that the file is
not a dynamic executable.

This change uses patchelf to directly analyze the DT_NEEDED tags in the
target files instead, which correctly works across architectures. It
also updates the use of objdump to be prefix-aware $OBJDUMP (which would
have been required in the PR mentioned above, but we never made it that
far into the script execution).

(cherry picked from commit b79483d)
jsoo1 pushed a commit to awakesecurity/nixpkgs that referenced this pull request Jul 6, 2022
In NixOS#84415, autoPatchelfHook was taught to use the correct path to the
readelf binary when a crossSystem is specified. Unfortunately, the
remainder of the functionality in the script depended on ldd, which only
reads ELF files of its own architecture. It has the further unfortunate
quality of not reporting any useful error, but rather that the file is
not a dynamic executable.

This change uses patchelf to directly analyze the DT_NEEDED tags in the
target files instead, which correctly works across architectures. It
also updates the use of objdump to be prefix-aware $OBJDUMP (which would
have been required in the PR mentioned above, but we never made it that
far into the script execution).

(cherry picked from commit b79483d)
jsoo1 pushed a commit to awakesecurity/nixpkgs that referenced this pull request Jul 6, 2022
In NixOS#84415, autoPatchelfHook was taught to use the correct path to the
readelf binary when a crossSystem is specified. Unfortunately, the
remainder of the functionality in the script depended on ldd, which only
reads ELF files of its own architecture. It has the further unfortunate
quality of not reporting any useful error, but rather that the file is
not a dynamic executable.

This change uses patchelf to directly analyze the DT_NEEDED tags in the
target files instead, which correctly works across architectures. It
also updates the use of objdump to be prefix-aware $OBJDUMP (which would
have been required in the PR mentioned above, but we never made it that
far into the script execution).

(cherry picked from commit b79483d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants