Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(nix): refactor, fix library packages #1080

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/Jenkinsfile.nix-flake
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ pipeline {
steps { script {
sh("""#!/usr/bin/env bash
${nix._sourceProfileInline()}
nix build --print-out-paths .#library
nix build --print-out-paths .#dynamic-library
""")
} }
}
stage('Check') {
steps {
sh 'ldd ./result/bin/c'
sh 'ldd ./result/bin/libgowaku.a'
Copy link
Member

@richard-ramos richard-ramos Apr 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See prev comment.

}
}
}
Expand Down
36 changes: 36 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
pkgs ? import <nixpkgs> { },
self ? ./.,
subPkgs ? "cmd/waku",
ldflags ? [],
cgoLdflags ? "",
output ? null,
commit ? builtins.substring 0 7 (self.rev or "dirty"),
version ? builtins.readFile ./VERSION,
}:

pkgs.buildGo120Module {
name = "go-waku";
src = self;

subPackages = subPkgs;
tags = ["gowaku_no_rln"];
ldflags = [
"-X github.com/waku-org/go-waku/waku/v2/node.GitCommit=${commit}"
"-X github.com/waku-org/go-waku/waku/v2/node.Version=${version}"
] ++ ldflags;
CGO_LDFLAGS = cgoLdflags;
GOGCCFLAGS = "-fPIC";
doCheck = false;

# Otherwise library would be just called bin/c.
postInstall = if builtins.isString output then ''
mv $out/bin/* $out/bin/${output}
'' else "";

# FIXME: This needs to be manually changed when updating modules.
vendorHash = "sha256-pNkh5ZJEhC/X/SoqfWcm3w7W1EGOT3m2dzePM/XuA9w=";

# Fix for 'nix run' trying to execute 'go-waku'.
meta = { mainProgram = "waku"; };
}
31 changes: 23 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,32 @@
meta = { mainProgram = "waku"; };
};
in rec {
packages = forAllSystems (system: {
node = buildPackage system ["cmd/waku"];
library = buildPackage system ["library/c"];
packages = forAllSystems (system: let
pkgs = pkgsFor.${system};
buildPackage = pkgs.callPackage ./default.nix;
in rec {
default = node;
node = buildPackage {
inherit self;
subPkgs = ["cmd/waku"];
};
static-library = buildPackage {
inherit self;
subPkgs = ["library/c"];
ldflags = ["-buildmode=c-archive"];
output = "libgowaku.a";
};
dynamic-library = buildPackage {
inherit self;
subPkgs = ["library/c"];
ldflags = ["-buildmode=c-shared"];
cgoLdflags = "-Wl,-Bsymbolic,-soname,libgowaku.so.0";
output = "libgowaku.so";
};
});

defaultPackage = forAllSystems (system:
buildPackage system ["cmd/waku"]
);

devShells = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
pkgs = pkgsFor.${system};
inherit (pkgs) lib stdenv mkShell;
in {
default = mkShell {
Expand Down
Loading