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

gobject-introspection: Conditionalize depsTargetTargetPropagated #353237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Artturin
Copy link
Member

@Artturin Artturin commented Nov 2, 2024

Fixes ↓

nix-repl> pkgsCross.x86_64-freebsd.pkgsBuildHost.gobject-introspection
error: Don't know how to run x86_64-unknown-freebsd executables.

The unwrapped already doesn't error

nix-repl> pkgsCross.x86_64-freebsd.pkgsBuildHost.gobject-introspection-unwrapped
«derivation /nix/store/xq4q4vigy2glmfng2h6bbr4sysyk8ipz-gobject-introspection-1.82.0.drv»

https://www.github.com/NixOS/nixpkgs/blob/7b1cffdd2e13b2cdad5b37e259016efd0ea48fcd/pkgs/development/libraries/gobject-introspection/default.nix#L114

It's caused by depsTargetTargetPropagated = [ overridenTargetUnwrappedGir ]; in the wrapper

In graphene there is
PATH=${python3.withPackages (pp: [ pp.pygobject3 pp.tappy ])}/bin:$PATH patchShebangs tests/introspection.py

Which causes the Don't know error in pkgsCross.x86_64-freebsd.pkgsBuildHost.graphene

because python3 and pygobject3 will be from pkgsHostTarget

and then pygobject3 has gobject-introspection from pkgsHostTarget

and then that gobject-introspection will have pkgsCross.x86_64-freebsd.pkgsCross.x86_64-freebsd.buildPackages.pkgsTargetTarget.gobject-introspection.gobject-introspection in depsTargetTargetPropagated

To test that importing the python library gi works without depsTargetTargetPropagated

let
  pkgs =
    (import ./. {
      crossSystem = (import ./lib).systems.examples.aarch64-multiplatform;
      # On `master` uncomment this and comment `propagatedBuildInputs` below and you'll get
      # error: Don't know how to run x86_64-unknown-freebsd executables.
      #crossSystem = (import ./lib).systems.examples.x86_64-freebsd;
      overlays = [
        (_: prev: {
          pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
            (_: pprev: {
              pygobject3-test = pprev.pygobject3.overrideAttrs {
                propagatedBuildInputs = [
                  pprev.pycairo
                  (prev.gobject-introspection.overrideAttrs { depsTargetTargetPropagated = [ ]; })
                ];
              };
            })
          ];
        })
      ];
    }).pkgs;
  pyr = pkgs.pkgsBuildHost.python3Packages.python.withPackages (pp: [ pp.pygobject3-test ]);
in
pkgs.pkgsBuildBuild.runCommand "test" { } ''
  "${pyr.interpreter}" -c "import gi" && touch "$out"
''

Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

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

Good golly.

@Artturin Artturin added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Nov 3, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 0 This PR does not cause any packages to rebuild labels Nov 3, 2024
@alyssais
Copy link
Member

alyssais commented Nov 3, 2024

What's the propagation needed for in the first place?

@Artturin
Copy link
Member Author

Artturin commented Nov 3, 2024

What's the propagation needed for in the first place?

# a comment for both depsTargetTargetPropagated's

# when cross-compiling and using the wrapper then when a package looks up the g_ir_X

We also did it so we have to add gobject-introspection to only one dependency attribute at a time

Yeah its a hack but so far it's been working quite well invisibly.

The girs running by emulator might also have looked for something targetOffset but I do not remember

export targetgir="${lib.getDev overridenTargetUnwrappedGir}"

@wegank wegank added the 12.approvals: 2 This PR was reviewed and approved by two reputable people label Nov 3, 2024
Fixes ↓

```
nix-repl> pkgsCross.x86_64-freebsd.pkgsBuildHost.gobject-introspection
error: Don't know how to run x86_64-unknown-freebsd executables.
```

The unwrapped already doesn't error

```
nix-repl> pkgsCross.x86_64-freebsd.pkgsBuildHost.gobject-introspection-unwrapped
«derivation /nix/store/xq4q4vigy2glmfng2h6bbr4sysyk8ipz-gobject-introspection-1.82.0.drv»
```

https://www.github.com/NixOS/nixpkgs/blob/7b1cffdd2e13b2cdad5b37e259016efd0ea48fcd/pkgs/development/libraries/gobject-introspection/default.nix#L114

It's caused by `depsTargetTargetPropagated = [ overridenTargetUnwrappedGir ];` in the wrapper

In `graphene` there is
`PATH=${python3.withPackages (pp: [ pp.pygobject3 pp.tappy ])}/bin:$PATH patchShebangs tests/introspection.py`

Which causes the `Don't know` error in `pkgsCross.x86_64-freebsd.pkgsBuildHost.graphene`

because `python3` and `pygobject3` will be from `pkgsHostTarget`

and then `pygobject3` has `gobject-introspection` from `pkgsHostTarget`

and then that `gobject-introspection` will have `pkgsCross.x86_64-freebsd.pkgsCross.x86_64-freebsd.buildPackages.pkgsTargetTarget.gobject-introspection.gobject-introspection` in `depsTargetTargetPropagated`

To test that importing the python library `gi` works without `depsTargetTargetPropagated`

```nix
let
  pkgs =
    (import ./. {
      crossSystem = (import ./lib).systems.examples.aarch64-multiplatform;
      # On `master` uncomment this and comment `propagatedBuildInputs` below and you'll get
      # error: Don't know how to run x86_64-unknown-freebsd executables.
      #crossSystem = (import ./lib).systems.examples.x86_64-freebsd;
      overlays = [
        (_: prev: {
          pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
            (_: pprev: {
              pygobject3-test = pprev.pygobject3.overrideAttrs {
                propagatedBuildInputs = [
                  pprev.pycairo
                  (prev.gobject-introspection.overrideAttrs { depsTargetTargetPropagated = [ ]; })
                ];
              };
            })
          ];
        })
      ];
    }).pkgs;
  pyr = pkgs.pkgsBuildHost.python3Packages.python.withPackages (pp: [ pp.pygobject3-test ]);
in
pkgs.pkgsBuildBuild.runCommand "test" { } ''
  "${pyr.interpreter}" -c "import gi" && touch "$out"
''
```
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 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 0 This PR does not cause any packages to rebuild 12.approvals: 2 This PR was reviewed and approved by two reputable people
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants