Skip to content

Commit

Permalink
protobuf nix
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdbrock committed Oct 15, 2024
1 parent d25a760 commit 7b7fb97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
inherit system;
config = { };
overlays = builtins.attrValues self.overlays ++ [
(prev: final: import ./nix/protobuf.nix {pkgs = prev;})
(prev: final: import ./nix/protobuf.nix final)
(prev: final: {
# This plugin path won't work because it's relative to the pwd
protoc-gen-purescript = prev.writeScriptBin "protoc-gen-purescript" ''
Expand Down
29 changes: 15 additions & 14 deletions nix/protobuf.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ pkgs ? import <nixpkgs> { } }:
{ stdenv, lib, fetchFromGitHub, autogen, automake, autoconf, libtool, rsync, cmake, ... }:
# pkgs ? import <nixpkgs> { } }:

# The protobuf derivation in nixpkgs does not include the conformance test
# runners.
Expand Down Expand Up @@ -66,7 +67,7 @@ let
};
protobuf_repo_v23_2 = rec {
ref = "v23.2";
src = pkgs.fetchFromGitHub {
src = fetchFromGitHub {
owner = "protocolbuffers";
repo = "protobuf";
rev = "v23.2";
Expand All @@ -76,7 +77,7 @@ let
};
protobuf_repo_v24_4 = rec {
ref = "v24.4";
src = pkgs.fetchFromGitHub {
src = fetchFromGitHub {
owner = "protocolbuffers";
repo = "protobuf";
rev = "v24.4";
Expand All @@ -86,7 +87,7 @@ let
};
protobuf_repo_v28_2= rec {
ref = "v28.2";
src = pkgs.fetchFromGitHub {
src = fetchFromGitHub {
owner = "protocolbuffers";
repo = "protobuf";
rev = "v28.2";
Expand All @@ -104,9 +105,9 @@ let
#
# See the Travis test runner script
# https://github.com/protocolbuffers/protobuf/blob/master/tests.sh
mkProtobuf = repo: pkgs.stdenv.mkDerivation {
mkProtobuf = repo: stdenv.mkDerivation {
name = "protobuf-${repo.ref}";
nativeBuildInputs = with pkgs; [ autogen automake autoconf libtool rsync ];
nativeBuildInputs = [ autogen automake autoconf libtool rsync ];
src = repo.src;
# https://github.com/protocolbuffers/protobuf/blob/main/src/README.md#c-installation---unix
configurePhase = ''
Expand Down Expand Up @@ -139,21 +140,21 @@ let
and conformance .proto definitions.
'';
homepage = "https://github.com/xc-jp/purescript-protobuf";
license = pkgs.lib.licenses.bsd3;
license = lib.licenses.bsd3;
mainProgram = "protoc";
};
};

cmakeProtobuf = repo: pkgs.stdenv.mkDerivation {
cmakeProtobuf = repo: stdenv.mkDerivation {
name = "protobuf-${repo.ref}";
nativeBuildInputs = with pkgs; [ cmake rsync ];
nativeBuildInputs = [ cmake rsync ];
src = repo.src;
# https://github.com/protocolbuffers/protobuf/blob/main/src/README.md#c-installation---unix
cmakeFlags = [ "-Dprotobuf_BUILD_CONFORMANCE=ON" ];
postInstall =
let
conformance_rpath = pkgs.lib.makeLibraryPath [
pkgs.stdenv.cc.cc.lib
conformance_rpath = lib.makeLibraryPath [
stdenv.cc.cc.lib
];
in
''
Expand All @@ -165,11 +166,11 @@ let
# Conformance test runner
cp ./conformance_test_runner $out/bin/conformance_test_runner
# https://nixos.wiki/wiki/Packaging/Binaries#Creating_the_Derivation_for_upstream_Packaging
patchelf --set-interpreter "${pkgs.stdenv.cc.bintools.dynamicLinker}" --set-rpath "$out/lib:${conformance_rpath}" $out/bin/conformance_test_runner
patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" --set-rpath "$out/lib:${conformance_rpath}" $out/bin/conformance_test_runner
# Distribute the cpp conformance program as a test case
cp ./conformance_cpp $out/bin/conformance_cpp
patchelf --set-interpreter "${pkgs.stdenv.cc.bintools.dynamicLinker}" --set-rpath "$out/lib:${conformance_rpath}" $out/bin/conformance_cpp
patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" --set-rpath "$out/lib:${conformance_rpath}" $out/bin/conformance_cpp
'';
meta = {
description = "Google’s Protobuf built for purescript-protobuf";
Expand All @@ -179,7 +180,7 @@ let
and conformance .proto definitions.
'';
homepage = "https://github.com/xc-jp/purescript-protobuf";
license = pkgs.lib.licenses.bsd3;
license = lib.licenses.bsd3;
mainProgram = "protoc";
};
};
Expand Down

0 comments on commit 7b7fb97

Please sign in to comment.