I am trying to fix Stockfish build on Darwin, which has been broken for years.
I’ve managed to do it, I needed to set CXX
(because the Makefile uses g++
):
makeFlags = [ "PREFIX=$(out)" "ARCH=${arch}" "CXX=${stdenv.cc.targetPrefix}c++" ];
And I needed to disable LTO, which is broken on Darwin, so I needed to remove a few lines from the Makefile, but sed can do it easily:
preBuild = stdenv.lib.optionalString stdenv.isDarwin ''
sed -i.orig '/^\#\#\# 3.*Link Time Optimization/,/^\#\#\# 3/d' Makefile
'';
And it builds now without issues.
My problem is I need to set the proper value for ARCH
, this is, if the CPU supports SSE4.2, ARCH
should be "x86-64-modern"
instead of "x86-64"
(I am copying this from Homebrew’s formula). So, I tried to do this:
arch64 = if stdenv.hostPlatform.sse4_2Support then "x86-64-modern" else "x86-64";
arch = if stdenv.isx86_64 then arch64
else if stdenv.isi686 then "x86-32"
else "unknown";
But, even when building the derivation on a Macbook Pro which does supports SSE4.2,
all the SSE features of stdenv.hostPlatform
are set to false
and arch
is set to "x86-64"
.
Is there a way to make the system detect that it supports SSE4.2, or is it not supported on Darwin?