Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
pkgs/development/libraries/libsnark/darwin-fix-clock-gettime.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Adapted from https://github.com/zcash/libsnark/pull/10 | ||
|
||
diff --git a/depends/libff/libff/common/profiling.cpp b/depends/libff/libff/common/profiling.cpp | ||
index f2a1985..319149c 100755 | ||
--- a/depends/libff/libff/common/profiling.cpp | ||
+++ b/depends/libff/libff/common/profiling.cpp | ||
@@ -27,6 +27,13 @@ | ||
#include <proc/readproc.h> | ||
#endif | ||
|
||
+#ifdef __MACH__ | ||
+#include <time.h> | ||
+#include <sys/time.h> | ||
+#include <mach/clock.h> | ||
+#include <mach/mach.h> | ||
+#endif | ||
+ | ||
namespace libff { | ||
|
||
long long get_nsec_time() | ||
@@ -42,10 +49,20 @@ long long get_nsec_cpu_time() | ||
return 0; | ||
#else | ||
::timespec ts; | ||
+#ifdef __MACH__ | ||
+ clock_serv_t cclock; | ||
+ mach_timespec_t mts; | ||
+ host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); | ||
+ clock_get_time(cclock, &mts); | ||
+ mach_port_deallocate(mach_task_self(), cclock); | ||
+ ts.tv_sec = mts.tv_sec; | ||
+ ts.tv_nsec = mts.tv_nsec; | ||
+#else | ||
if ( ::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) ) | ||
throw ::std::runtime_error("clock_gettime(CLOCK_PROCESS_CPUTIME_ID) failed"); | ||
// If we expected this to work, don't silently ignore failures, because that would hide the problem and incur an unnecessarily system-call overhead. So if we ever observe this exception, we should probably add a suitable #ifdef . | ||
//TODO: clock_gettime(CLOCK_PROCESS_CPUTIME_ID) is not supported by native Windows. What about Cygwin? Should we #ifdef on CLOCK_PROCESS_CPUTIME_ID or on __linux__? | ||
+#endif | ||
return ts.tv_sec * 1000000000ll + ts.tv_nsec; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ stdenv, fetchFromGitHub, cmake, pkgconfig, openssl, boost, gmp, procps, fetchpatch, patchutils }: | ||
|
||
let | ||
rev = "9e6b19ff15bc19fba5da1707ba18e7f160e5ed07"; | ||
inherit (stdenv) lib; | ||
in stdenv.mkDerivation rec { | ||
name = "libsnark-pre${version}"; | ||
version = stdenv.lib.substring 0 8 rev; | ||
|
||
buildInputs = [ cmake pkgconfig openssl boost gmp ] ++ lib.optional stdenv.hostPlatform.isLinux procps; | ||
|
||
cmakeFlags = lib.optionals stdenv.hostPlatform.isDarwin [ "-DWITH_PROCPS=OFF" "-DWITH_SUPERCOP=OFF" ]; | ||
|
||
src = fetchFromGitHub { | ||
inherit rev; | ||
owner = "scipr-lab"; | ||
repo = "libsnark"; | ||
sha256 = "13f02qp2fmfhvxlp4xi69m0l8r5nq913l2f0zwdk7hl46lprfdca"; | ||
fetchSubmodules = true; | ||
}; | ||
|
||
patches = [ ./darwin-fix-clock-gettime.patch ]; | ||
|
||
enableParallelBuilding = true; | ||
|
||
meta = with stdenv.lib; { | ||
description = "C++ library for zkSNARKs"; | ||
homepage = https://github.com/scipr-lab/libsnark; | ||
license = licenses.mit; | ||
platforms = stdenv.lib.platforms.linux ++ stdenv.lib.platforms.darwin; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters