|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + rustPlatform, |
| 5 | + fetchFromGitHub, |
| 6 | + nix-update-script, |
| 7 | + testers, |
| 8 | +}: |
| 9 | + |
| 10 | +rustPlatform.buildRustPackage (finalAttrs: { |
| 11 | + pname = "temporal_capi"; |
| 12 | + version = "0.1.2"; |
| 13 | + |
| 14 | + src = fetchFromGitHub { |
| 15 | + owner = "boa-dev"; |
| 16 | + repo = "temporal"; |
| 17 | + tag = "v${finalAttrs.version}"; |
| 18 | + hash = "sha256-JmNYoskoQZewmWAU/SUBdjKdN+pnpMdLZUVv+jysS5A="; |
| 19 | + }; |
| 20 | + |
| 21 | + cargoHash = "sha256-jIPbroAtS7D/l4QJtGCgXNa7QaQLdsF4Gh9O4NaRBCw="; |
| 22 | + |
| 23 | + postPatch = '' |
| 24 | + # Force crate-type to include staticlib |
| 25 | + echo ' |
| 26 | + [lib] |
| 27 | + crate-type = ["${if stdenv.hostPlatform.isStatic then "staticlib" else "cdylib"}"] |
| 28 | + ' >> temporal_capi/Cargo.toml |
| 29 | + ''; |
| 30 | + |
| 31 | + cargoBuildFlags = [ |
| 32 | + "--package" |
| 33 | + "temporal_capi" |
| 34 | + "--features" |
| 35 | + "zoneinfo64,compiled_data" |
| 36 | + ]; |
| 37 | + |
| 38 | + installPhase = '' |
| 39 | + runHook preInstall |
| 40 | +
|
| 41 | + install -Dm644 target/*/release/libtemporal_capi.* -t $out/lib |
| 42 | +
|
| 43 | + install -Dm644 -t $out/include/temporal_rs \ |
| 44 | + temporal_capi/bindings/cpp/temporal_rs/*.hpp |
| 45 | + install -Dm644 -t $out/include \ |
| 46 | + temporal_capi/bindings/c/*.h |
| 47 | +
|
| 48 | + runHook postInstall |
| 49 | + ''; |
| 50 | + postInstall = '' |
| 51 | + mkdir $out/lib/pkgconfig |
| 52 | + cat -> $out/lib/pkgconfig/temporal_capi.pc <<EOF |
| 53 | + prefix=$out |
| 54 | + exec_prefix=''${prefix} |
| 55 | + libdir=''${exec_prefix}/lib |
| 56 | + includedir=''${prefix}/include |
| 57 | +
|
| 58 | + Name: temporal_capi |
| 59 | + Description: C API for temporal_rs |
| 60 | + Version: ${finalAttrs.version} |
| 61 | + Libs: -L''${libdir} -ltemporal_capi |
| 62 | + Cflags: -I''${includedir} |
| 63 | + EOF |
| 64 | + ''; |
| 65 | + postFixup = lib.optional (stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isStatic) '' |
| 66 | + ${stdenv.cc.targetPrefix}install_name_tool -id "$out/lib/libtemporal_capi.dylib" "$out/lib/libtemporal_capi.dylib" |
| 67 | + ''; |
| 68 | + |
| 69 | + # We don't want to run Rust checks, we only check the resulting lib using C/C++ in the installCheckPhase. |
| 70 | + doCheck = false; |
| 71 | + doInstallCheck = true; |
| 72 | + nativeInstallCheckInputs = [ stdenv.cc ]; |
| 73 | + installCheckPhase = '' |
| 74 | + runHook preInstallCheck |
| 75 | +
|
| 76 | + cc -L $out/lib -I $out/include temporal_capi/tests/c/simple.c -ltemporal_capi -lm -o c_test |
| 77 | + ./c_test |
| 78 | + c++ -L $out/lib -I $out/include temporal_capi/tests/cpp/simple.cpp -ltemporal_capi -lm -o cpp_test |
| 79 | + ./cpp_test |
| 80 | +
|
| 81 | + runHook postInstallCheck |
| 82 | + ''; |
| 83 | + |
| 84 | + passthru.tests = { |
| 85 | + pkg-config = testers.hasPkgConfigModules { |
| 86 | + package = finalAttrs.finalPackage; |
| 87 | + moduleNames = [ "temporal_capi" ]; |
| 88 | + }; |
| 89 | + updateScript = nix-update-script { }; |
| 90 | + }; |
| 91 | + |
| 92 | + meta = with lib; { |
| 93 | + description = "A Rust implementation of ECMAScript's Temporal API"; |
| 94 | + homepage = "https://github.com/boa-dev/temporal"; |
| 95 | + changelog = "https://github.com/boa-dev/temporal/blob/${finalAttrs.src.rev}/CHANGELOG.md"; |
| 96 | + license = with licenses; [ |
| 97 | + asl20 |
| 98 | + mit |
| 99 | + ]; |
| 100 | + maintainers = with maintainers; [ aduh95 ]; |
| 101 | + }; |
| 102 | +}) |
0 commit comments