Skip to content

Commit

Permalink
build sst_dump tool
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Dec 16, 2022
1 parent 9cbf1df commit 5bca411
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 29 deletions.
14 changes: 3 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
inputs.nixpkgs.follows = "nixpkgs";
inputs.utils.follows = "flake-utils";
};
rocksdb-src = {
url = "github:facebook/rocksdb/v7.7.3";
flake = false;
};
};

outputs = { self, nixpkgs, nix-bundle-exe, gomod2nix, flake-utils, rocksdb-src }:
outputs = { self, nixpkgs, nix-bundle-exe, gomod2nix, flake-utils }:
let
rev = self.shortRev or "dirty";
mkApp = drv: {
Expand Down Expand Up @@ -57,7 +53,7 @@
}
)
) // {
overlay = final: prev: {
overlay = final: _: {
bundle-exe = import nix-bundle-exe { pkgs = final; };
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
Expand All @@ -66,11 +62,7 @@
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| "${gzip}/bin/gzip" -9 > $out
'';
rocksdb = (prev.rocksdb.override { enableJemalloc = true; }).overrideAttrs (old: rec {
pname = "rocksdb";
version = "7.7.3";
src = rocksdb-src;
});
rocksdb = final.callPackage ./nix/rocksdb.nix { enableJemalloc = true; };
} // (with final;
let
matrix = lib.cartesianProductOfSets {
Expand Down
8 changes: 2 additions & 6 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ import sources.nixpkgs {
hermes = pkgs.callPackage ./hermes.nix { src = sources.ibc-rs; };
})
(_: pkgs: { test-env = import ./testenv.nix { inherit pkgs; }; })
(_: pkgs: {
rocksdb = (pkgs.rocksdb.override { enableJemalloc = true; }).overrideAttrs (old: rec {
pname = "rocksdb";
version = "7.7.3";
src = sources.rocksdb;
});
(final: _: {
rocksdb = final.callPackage ./rocksdb.nix { enableJemalloc = true; };
})
(_: pkgs: {
cosmovisor = pkgs.buildGo117Module rec {
Expand Down
92 changes: 92 additions & 0 deletions nix/rocksdb.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{ lib, stdenv
, fetchFromGitHub
, fetchpatch
, cmake
, ninja
, bzip2
, lz4
, snappy
, zlib
, zstd
, enableJemalloc ? false, jemalloc
, enableLite ? false
, enableShared ? !stdenv.hostPlatform.isStatic
}:

stdenv.mkDerivation rec {
pname = "rocksdb";
version = "7.7.3";

src = fetchFromGitHub {
owner = "facebook";
repo = pname;
rev = "v${version}";
sha256 = "sha256-Np3HPTZYzyoPOKL0xgsLzcvOkceFiEQd+1nyGbg4BHo=";
};

nativeBuildInputs = [ cmake ninja ];

propagatedBuildInputs = [ bzip2 lz4 snappy zlib zstd ];

buildInputs = lib.optional enableJemalloc jemalloc;

outputs = [
"out"
"tools"
];

NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isGNU "-Wno-error=deprecated-copy -Wno-error=pessimizing-move"
+ lib.optionalString stdenv.cc.isClang "-Wno-error=unused-private-field -faligned-allocation";

cmakeFlags = [
"-DPORTABLE=1"
"-DWITH_JEMALLOC=${if enableJemalloc then "1" else "0"}"
"-DWITH_JNI=0"
"-DWITH_BENCHMARK_TOOLS=0"
"-DWITH_TESTS=1"
"-DWITH_TOOLS=0"
"-DWITH_CORE_TOOLS=1"
"-DWITH_BZ2=1"
"-DWITH_LZ4=1"
"-DWITH_SNAPPY=1"
"-DWITH_ZLIB=1"
"-DWITH_ZSTD=1"
"-DWITH_GFLAGS=0"
"-DUSE_RTTI=1"
"-DROCKSDB_INSTALL_ON_WINDOWS=YES" # harmless elsewhere
(lib.optional
(stdenv.hostPlatform.isx86 && stdenv.hostPlatform.isLinux)
"-DFORCE_SSE42=1")
(lib.optional enableLite "-DROCKSDB_LITE=1")
"-DFAIL_ON_WARNINGS=${if stdenv.hostPlatform.isMinGW then "NO" else "YES"}"
] ++ lib.optional (!enableShared) "-DROCKSDB_BUILD_SHARED=0";

# otherwise "cc1: error: -Wformat-security ignored without -Wformat [-Werror=format-security]"
hardeningDisable = lib.optional stdenv.hostPlatform.isWindows "format";

preInstall = ''
mkdir -p $tools/bin
cp tools/{ldb,sst_dump} $tools/bin/
'' + lib.optionalString stdenv.isDarwin ''
ls -1 $tools/bin/* | xargs -I{} install_name_tool -change "@rpath/librocksdb.7.dylib" $out/lib/librocksdb.dylib {}
'' + lib.optionalString stdenv.isLinux ''
ls -1 $tools/bin/* | xargs -I{} patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib {}
'';

# Old version doesn't ship the .pc file, new version puts wrong paths in there.
postFixup = ''
if [ -f "$out"/lib/pkgconfig/rocksdb.pc ]; then
substituteInPlace "$out"/lib/pkgconfig/rocksdb.pc \
--replace '="''${prefix}//' '="/'
fi
'';

meta = with lib; {
homepage = "https://rocksdb.org";
description = "A library that provides an embeddable, persistent key-value store for fast storage";
changelog = "https://github.com/facebook/rocksdb/raw/v${version}/HISTORY.md";
license = licenses.asl20;
platforms = platforms.all;
maintainers = with maintainers; [ adev magenbluten ];
};
}
12 changes: 0 additions & 12 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,5 @@
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/5342fc6fb59d0595d26883c3cadff16ce58e44f3.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"rocksdb": {
"branch": "v7.7.3",
"description": "A library that provides an embeddable, persistent key-value store for fast storage.",
"homepage": "http://rocksdb.org",
"owner": "facebook",
"repo": "rocksdb",
"rev": "eb9a80fe1f18017b4d7f4084e8f2554f12234822",
"sha256": "0yh472w1kwjrzcfl9245qy8wxjyd1c5wdx52707jmksq6qywg79n",
"type": "tarball",
"url": "https://github.com/facebook/rocksdb/archive/eb9a80fe1f18017b4d7f4084e8f2554f12234822.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}

0 comments on commit 5bca411

Please sign in to comment.