nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 rustPlatform,
4 writeText,
5 stdenv,
6}:
7
8{ version, src, ... }:
9
10let
11 rustDep = rustPlatform.buildRustPackage {
12 pname = "flutter_vodozemac-rs";
13 inherit version src;
14
15 sourceRoot = "${src.name}/rust";
16
17 cargoHash =
18 {
19 _0_2_2 = "sha256-Iw0AkHVjR1YmPe+C0YYBTDu5FsRk/ZpaRyBilcvqm6M=";
20 _0_3_0 = "sha256-eKKrcroV2yl/FV2WmgZWFPO5MPAGz0xCvpr0fgIuGZ4=";
21 _0_4_1 = "sha256-eKKrcroV2yl/FV2WmgZWFPO5MPAGz0xCvpr0fgIuGZ4=";
22 }
23 .${"_" + (lib.replaceStrings [ "." ] [ "_" ] version)} or (throw ''
24 Unsupported version of pub 'flutter_vodozemac': '${version}'
25 Please add cargoHash here. If the cargoHash
26 is the same with existing versions, add an alias here.
27 '');
28
29 passthru.libraryPath = "lib/libvodozemac_bindings_dart.so";
30 };
31
32 fakeCargokitCmake = writeText "FakeCargokit.cmake" ''
33 function(apply_cargokit target manifest_dir lib_name any_symbol_name)
34 set("''${target}_cargokit_lib" ${rustDep}/${rustDep.passthru.libraryPath} PARENT_SCOPE)
35 endfunction()
36 '';
37
38 getLibraryPath = ''
39 String _getLibraryPath() {
40 if (kIsWeb) {
41 return './';
42 }
43 try {
44 return Platform.resolvedExecutable + '/../lib/libvodozemac_bindings_dart.so';
45 } catch (_) {
46 return './';
47 }
48 }
49 '';
50in
51stdenv.mkDerivation {
52 pname = "flutter_vodozemac";
53 inherit version src;
54 passthru = src.passthru // {
55 # vodozemac-wasm in fluffychat will make use of it
56 inherit (rustDep) cargoDeps;
57 };
58
59 installPhase = ''
60 runHook preInstall
61
62 cp -r "$src" "$out"
63 pushd $out
64 chmod +rwx cargokit/cmake/cargokit.cmake
65 cp ${fakeCargokitCmake} cargokit/cmake/cargokit.cmake
66 chmod +rw lib/flutter_vodozemac.dart
67 substituteInPlace lib/flutter_vodozemac.dart \
68 --replace-warn "libraryPath: './'" "libraryPath: _getLibraryPath()"
69 echo "${getLibraryPath}" >> lib/flutter_vodozemac.dart
70 popd
71
72 runHook postInstall
73 '';
74}