1{ stdenv
2, lib
3, rustPlatform
4, rustc
5, callPackage
6, fetchFromGitHub
7, buildPythonPackage
8, libiconv
9, libffi
10, libxml2
11, ncurses
12, zlib
13}:
14
15let
16 common =
17 { pname
18 , buildAndTestSubdir
19 , cargoHash
20 , extraNativeBuildInputs ? [ ]
21 , extraBuildInputs ? [ ]
22 }: buildPythonPackage rec {
23 inherit pname;
24 version = "1.1.0";
25 format = "pyproject";
26
27 outputs = [ "out" ] ++ lib.optional (pname == "wasmer") "testsout";
28
29 src = fetchFromGitHub {
30 owner = "wasmerio";
31 repo = "wasmer-python";
32 rev = version;
33 hash = "sha256-nOeOhQ1XY+9qmLGURrI5xbgBUgWe5XRpV38f73kKX2s=";
34 };
35
36 cargoDeps = rustPlatform.fetchCargoTarball {
37 inherit src;
38 name = "${pname}-${version}";
39 sha256 = cargoHash;
40 };
41
42 nativeBuildInputs = (with rustPlatform; [ cargoSetupHook maturinBuildHook ])
43 ++ extraNativeBuildInputs;
44
45 postPatch = ''
46 # Workaround for metadata, that maturin 0.14 does not accept in Cargo.toml anymore
47 substituteInPlace ${buildAndTestSubdir}/Cargo.toml \
48 --replace "package.metadata.maturin" "broken"
49 '';
50
51 buildInputs = lib.optionals stdenv.isDarwin [ libiconv ]
52 ++ extraBuildInputs;
53
54 inherit buildAndTestSubdir;
55
56 postInstall = lib.optionalString (pname == "wasmer") ''
57 mkdir $testsout
58 cp -R tests $testsout/tests
59 '';
60
61 # check in passthru.tests.pytest because all packages are required to run the tests
62 doCheck = false;
63
64 passthru.tests = lib.optionalAttrs (pname == "wasmer") {
65 pytest = callPackage ./tests.nix { };
66 };
67
68 pythonImportsCheck = [ "${lib.replaceStrings ["-"] ["_"] pname}" ];
69
70 meta = with lib; {
71 description = "Python extension to run WebAssembly binaries";
72 homepage = "https://github.com/wasmerio/wasmer-python";
73 license = licenses.mit;
74 platforms = platforms.unix;
75 maintainers = [ ];
76 };
77 };
78in
79{
80 wasmer = common {
81 pname = "wasmer";
82 buildAndTestSubdir = "packages/api";
83 cargoHash = "sha256-twoog8LjQtoli+TlDipSuB7yLFkXQJha9BqobqgZW3Y=";
84 };
85
86 wasmer-compiler-cranelift = common {
87 pname = "wasmer-compiler-cranelift";
88 buildAndTestSubdir = "packages/compiler-cranelift";
89 cargoHash = "sha256-IqeMOY6emhIC7ekH8kIOZCr3JVkjxUg/lQli+ZZpdq4=";
90 };
91
92 wasmer-compiler-llvm = common {
93 pname = "wasmer-compiler-llvm";
94 buildAndTestSubdir = "packages/compiler-llvm";
95 cargoHash = "sha256-xawbf5gXXV+7I2F2fDSaMvjtFvGDBtqX7wL3c28TSbA=";
96 extraNativeBuildInputs = [ rustc.llvm ];
97 extraBuildInputs = [ libffi libxml2.out ncurses zlib ];
98 };
99
100 wasmer-compiler-singlepass = common {
101 pname = "wasmer-compiler-singlepass";
102 buildAndTestSubdir = "packages/compiler-singlepass";
103 cargoHash = "sha256-4nZHMCNumNhdGPOmHXlJ5POYP7K+VPjwhEUMgzGb/Rk=";
104 };
105}