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 broken = stdenv.isDarwin;
72 description = "Python extension to run WebAssembly binaries";
73 homepage = "https://github.com/wasmerio/wasmer-python";
74 license = licenses.mit;
75 platforms = platforms.unix;
76 maintainers = with maintainers; [ SuperSandro2000 ];
77 };
78 };
79in
80rec {
81 wasmer = common {
82 pname = "wasmer";
83 buildAndTestSubdir = "packages/api";
84 cargoHash = "sha256-twoog8LjQtoli+TlDipSuB7yLFkXQJha9BqobqgZW3Y=";
85 };
86
87 wasmer-compiler-cranelift = common {
88 pname = "wasmer-compiler-cranelift";
89 buildAndTestSubdir = "packages/compiler-cranelift";
90 cargoHash = "sha256-IqeMOY6emhIC7ekH8kIOZCr3JVkjxUg/lQli+ZZpdq4=";
91 };
92
93 wasmer-compiler-llvm = common {
94 pname = "wasmer-compiler-llvm";
95 buildAndTestSubdir = "packages/compiler-llvm";
96 cargoHash = "sha256-xawbf5gXXV+7I2F2fDSaMvjtFvGDBtqX7wL3c28TSbA=";
97 extraNativeBuildInputs = [ rustc.llvm ];
98 extraBuildInputs = [ libffi libxml2.out ncurses zlib ];
99 };
100
101 wasmer-compiler-singlepass = common {
102 pname = "wasmer-compiler-singlepass";
103 buildAndTestSubdir = "packages/compiler-singlepass";
104 cargoHash = "sha256-4nZHMCNumNhdGPOmHXlJ5POYP7K+VPjwhEUMgzGb/Rk=";
105 };
106}