timbertson / opam2nix

Generate nix expressions from opam packages
MIT License
93 stars 28 forks source link

fail building llvm #48

Open joprice opened 3 years ago

joprice commented 3 years ago

I can't seem to figure out how to provide llvm_config and cmake to llvm. I tried using overrides and adding them to buildInputs, but that doesn't help.

CTRL-C to give up.
source root is llvm-10.0.0.src
setting SOURCE_DATE_EPOCH to timestamp 1584975662 of file llvm-10.0.0.src/utils/yaml-bench/YAMLBench.cpp
patching sources
+ /nix/store/dd1x528p6k46ivnmz3p7apw2dzibik5j-ocaml4.10.0-opam2nix-1.1.0/bin/opam2nix invoke patch
Loading /nix/store/ljr36snxjjb3l13nn96wbhdv5lmgi21n-opam/opam
 + cp -r --no-preserve=mode --dereference /nix/store/ljr36snxjjb3l13nn96wbhdv5lmgi21n-opam/files/link-META.patch /nix/store/ljr36snxjjb3l13nn96wbhdv5lmgi21n-opam/files/install.sh /nix/store/ljr36snxjjb3l13nn96wbhdv5lmgi21n-opam/files/META.patch /nix/store/ljr36snxjjb3l13nn96wbhdv5lmgi21n-opam/files/fix-shared.patch ./
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
findlibPreBuildAction
building
+ /nix/store/dd1x528p6k46ivnmz3p7apw2dzibik5j-ocaml4.10.0-opam2nix-1.1.0/bin/opam2nix invoke build
Loading /nix/store/ljr36snxjjb3l13nn96wbhdv5lmgi21n-opam/opam
creating /nix/store/9xzw6slvlryzn020qgbk7qgg51qqla8s-llvm-10.0.0/bin
creating /nix/store/9xzw6slvlryzn020qgbk7qgg51qqla8s-llvm-10.0.0/lib/ocaml/4.10.0/site-lib/stublibs
installing
+ /nix/store/dd1x528p6k46ivnmz3p7apw2dzibik5j-ocaml4.10.0-opam2nix-1.1.0/bin/opam2nix invoke install
Loading /nix/store/ljr36snxjjb3l13nn96wbhdv5lmgi21n-opam/opam
WARN: opam var conf-llvm:config not found...
WARN: opam var conf-cmake:cmd not found...
 + bash -ex install.sh  /nix/store/9xzw6slvlryzn020qgbk7qgg51qqla8s-llvm-10.0.0/lib/ocaml/4.10.0/site-lib  make
+ llvm_config=
+ libdir=/nix/store/9xzw6slvlryzn020qgbk7qgg51qqla8s-llvm-10.0.0/lib/ocaml/4.10.0/site-lib
+ cmake=
+ make=make
+ '' --link-static --libs
install.sh: line 36: : command not found
+ '' --link-static --libs
install.sh: line 40: : command not found
+ '' --link-shared --libs
install.sh: line 43: : command not found
+ echo WTF...
WTF...
+ exit 1
Command failed.

The version in nix does work https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/ocaml-modules/llvm/default.nix, but I think it works differently because it doesn't rely on conf-llvm.

timbertson commented 3 years ago

Hmm, probably because of:

WARN: opam var conf-llvm:config not found...
WARN: opam var conf-cmake:cmd not found...

The manual says:

Extra variables can be defined by any package at installation time, using a .config file with a variables {} field.

Which just seems really hard to implement, so I didn't. This is the first use case I've seen that actually depends on it.

I don't know what that variable ends up being in a real opam, you might need to override the installPhase to pass in those values manually.

joprice commented 2 years ago

How do I get access to opam in the installPhase to set them? If I can't access it, maybe I can just modify the opam file by substituting %{conf-llvm:config}% with the path to conf-llvm and the other to cmake, but I'm not sure how to get a reference to the opam file.


opam-version: "2.0"
maintainer: "Kate <kit.ty.kate@disroot.org>"
authors: [
  "whitequark <whitequark@whitequark.org>"
  "The LLVM team"
]
license: "MIT"
doc: "http://llvm.moe/ocaml"
bug-reports: "http://llvm.org/bugs/"
dev-repo: "git+http://llvm.org/git/llvm.git"
homepage: "http://llvm.moe"
install: [
  ["bash" "-ex" "install.sh" "%{conf-llvm:config}%" lib "%{conf-cmake:cmd}%" make]
]
depends: [
  "ocaml" {>= "4.00.0"}
  "ctypes" {>= "0.4"}
  "ounit" {with-test}
  "ocamlfind" {build}
  "conf-llvm" {build & = version}
  "conf-python-2-7" {build}
  "conf-cmake" {build}
]
patches: [
  "fix-shared.patch"
]
synopsis: "The OCaml bindings distributed with LLVM"
description: "Note: LLVM should be installed first."
extra-files: [
  ["link-META.patch" "md5=ef4ebb8706be2ed402f31fc351d7dc75"]
  ["install.sh" "md5=76fb00c644110c73d04b15a2afb1aaf3"]
  ["fix-shared.patch" "md5=dce86b1db352332968ceb6d042b408a8"]
  ["META.patch" "md5=1d0af08bab7a0f831f68849b6556e414"]
]
url {
  src: "https://github.com/llvm/llvm-project/releases/download/llvmorg-11.1.0/llvm-11.1.0.src.tar.xz"
  checksum: "sha256=ce8508e318a01a63d4e8b3090ab2ded3c598a50258cc49e2625b9120d4c03ea5"
}```
timbertson commented 2 years ago

How do I get access to opam in the installPhase to set them

You wouldn't be able to access opam, opam2nix never actually uses opam. I was thinking you could do this:

{ pkgs, selection }: {
    llvm = super: super.overrideAttrs (attrs: {
        installPhase = ''
            bash -ex install.sh "${selection.conf-llvm}/config" lib "${selection.conf-cmake}/cmd" make
        '';
    });
}

...but now that I write it out explicitly, that's not right because those are file paths.

You might have to scout around in the built conf-llvm derivation, but somewhere there should be a .config file. If you can find that, you can possibly do some hacky sed / python to pull out the values you need.

If that file doesn't end up installed, it could well be an overlayed file from the opam repository itself (i.e. not in $out, nor in src). That would be... inconvenient. If that's the case, it might make sense for opam2nix to add explicit support for this kind of thing, perhaps by at least processing that file and spitting out a opam-config directory (in $out) with a file for each key, containing the evaluated value. I don't know how difficult this would be to implement (it depends what you need to evaluate those variables)

joprice commented 2 years ago

I was able to get it a bit further along with this:

 installPhase = ''
   bash -ex install.sh  "${pkgs.llvmPackages_11.llvm}/bin/llvm-config" lib "${pkgs.cmake}/bin/cmake" make
'';

But it then ends up failing with the following error

+ /nix/store/zdqiff42s60mc4cqgfwm6kalc449b5xx-cmake-3.19.7/bin/cmake -P bindings/ocaml/cmake_install.cmake
-- Install configuration: "Release"
CMake Error at bindings/ocaml/llvm/cmake_install.cmake:41 (file):
  file cannot create directory: /var/empty/local/lib/llvm.  Maybe need
  administrative privileges.
Call Stack (most recent call first):
  bindings/ocaml/cmake_install.cmake:42 (include)
timbertson commented 2 years ago

/var/empty/local/lib/llvm <- that looks pretty suss, I'm not sure it has much to do with opam2nix at this point :disappointed: . I don't know what the llvm opam package is, can you just substitute it for nixpkgs own llvm? Or does it have particular ocaml smarts?

joprice commented 2 years ago

It's an ocaml module for llvm codegen https://llvm.moe/ocaml/index.html, https://github.com/llvm/llvm-project/tree/main/llvm/bindings/ocaml.

joprice commented 2 years ago

I was able to get it working for now by overriding llvm and ctypes. Ctypes had to be overridden due to a bincompat issue.

override = {}: {
  llvm = super: ocaml-ng.ocamlPackages_4_12.llvm;
  ctypes = super: ocaml-ng.ocamlPackages_4_12.ctypes;
  ...