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