1{ stdenv
2, lib
3, rustPlatform
4, callPackage
5, fetchFromGitHub
6, buildPythonPackage
7, libiconv
8, llvm_11
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.0.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-I1GfjLaPYMIHKh2m/5IQepUsJNiVUEJg49wyuuzUYtY=";
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 buildInputs = lib.optionals stdenv.isDarwin [ libiconv ]
46 ++ extraBuildInputs;
47
48 inherit buildAndTestSubdir;
49
50 postInstall = lib.optionalString (pname == "wasmer") ''
51 mkdir $testsout
52 cp -R tests $testsout/tests
53 '';
54
55 # check in passthru.tests.pytest because all packages are required to run the tests
56 doCheck = false;
57
58 passthru.tests = lib.optionalAttrs (pname == "wasmer") {
59 pytest = callPackage ./tests.nix { };
60 };
61
62 pythonImportsCheck = [ "${lib.replaceStrings ["-"] ["_"] pname}" ];
63
64 meta = with lib; {
65 description = "Python extension to run WebAssembly binaries";
66 homepage = "https://github.com/wasmerio/wasmer-python";
67 license = licenses.mit;
68 platforms = platforms.unix;
69 maintainers = with maintainers; [ SuperSandro2000 ];
70 };
71 };
72in
73rec {
74 wasmer = common {
75 pname = "wasmer";
76 buildAndTestSubdir = "packages/api";
77 cargoHash = "sha256-txOOia1C4W+nsXuXp4EytEn82CFfSmiOYwRLC4WPImc=";
78 };
79
80 wasmer-compiler-cranelift = common {
81 pname = "wasmer-compiler-cranelift";
82 buildAndTestSubdir = "packages/compiler-cranelift";
83 cargoHash = "sha256-cHgAUwqnbQV3E5nUYGYQ48ntbIFfq4JXfU5IrSFZ3zI=";
84 };
85
86 wasmer-compiler-llvm = common {
87 pname = "wasmer-compiler-llvm";
88 buildAndTestSubdir = "packages/compiler-llvm";
89 cargoHash = "sha256-Jm22CC5S3pN/vdVvsGZdvtoAgPzWVLto8wavSJdxY3A=";
90 extraNativeBuildInputs = [ llvm_11 ];
91 extraBuildInputs = [ libffi libxml2.out ncurses zlib ];
92 };
93
94 wasmer-compiler-singlepass = common {
95 pname = "wasmer-compiler-singlepass";
96 buildAndTestSubdir = "packages/compiler-singlepass";
97 cargoHash = "sha256-lmqEo3+jYoN+4EEYphcoE4b84jdFcvYVycjrJ956Bh8=";
98 };
99}