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

failure building torch #64

Open
joprice opened this issue Aug 20, 2021 · 2 comments
Open

failure building torch #64

joprice opened this issue Aug 20, 2021 · 2 comments

Comments

@joprice
Copy link
Contributor

joprice commented Aug 20, 2021

I'm trying to build torch with opam2nix, which uses libtorch. The latter's opam file uses the extra-source directive to pull in libtorch:

opam-version: "2.0"
  homepage: "https://github.com/LaurentMazare/ocaml-torch"
  maintainer: "lmazare@gmail.com"
  bug-reports: "https://github.com/LaurentMazare/ocaml-torch/issues"
  authors: [
    "Laurent Mazare"
  ]
  install: [
    [
      "sh"
      "-c"
      "test -d %{lib}%/libtorch/lib/libtorch.so || ( unzip libtorch-macos.zip && mv -f libtorch %{lib}%/ && tar xzf mklml-maco  s.tgz && mv -f mklml_mac_2019.0.1.20181227/lib/libmklml.dylib %{lib}%/libtorch/lib/ && mv -f mklml_mac_2019.0.1.20181227/lib  /libiomp5.dylib %{lib}%/libtorch/lib/ )"
    ]
  ]
  depexts: [
    ["libomp"] {os-distribution = "homebrew"}
  ]
  synopsis: "LibTorch library package"
  description: """
  This is used by the torch package to trigger the install of the
  libtorch library."""
  extra-source "libtorch-macos.zip" {
    src: "https://download.pytorch.org/libtorch/cpu/libtorch-macos-1.8.0.zip"
    checksum: "md5=23f07569e0c942260c8b13fa8c3289b8"
  }
  extra-source "mklml-macos.tgz" {
    src: "https://github.com/intel/mkl-dnn/releases/download/v0.17.2/mklml_mac_2019.0.1.20181227.tgz"
    checksum: "md5=a8b4b158dc8e7aad13c0d594a9a8d241"
  }
  available: arch = "x86_64" & os = "macos"

I don't see this mentioned in opam2nix, so I assume it needs to be parsed and converted to a nix expression. If that's the case, I could try to work on it if needed. In the meantime, to work around this, I'll try overriding that package.

@joprice
Copy link
Contributor Author

joprice commented Aug 20, 2021

I got it to build with these overrides:

libtorch =
      stdenv.mkDerivation {
        name = "libtorch";
        version = "1.8.0";
        src = pkgs.fetchzip {
          url = "https://download.pytorch.org/libtorch/cpu/libtorch-macos-1.8.0.zip";
          sha256 = "109c85kjm71d9jzir2ha7w6k97f02ny2cqipb8rdrlq1sg75nnap";
        };
        installPhase = ''
          mkdir -p $out
          cp -r include/ $out/include
          cp -r lib/ $out/lib
        '';
      };
...
override = {selection}: {
        libtorch = _: libtorch;
        torch = super: super.overrideAttrs (
          super: {
            LIBTORCH = libtorch;
            buildInputs = (super.buildInputs or []) ++ [ pkgs.darwin.apple_sdk.frameworks.IOKit ];
          }
      );
...

@timbertson
Copy link
Owner

Yeah I've never encountered the extra-source directive before, so if you want to work on a PR to add support that'd be great 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants