Installing GDB with All Targets on Mac with Homebrew - macos

I'm unable to install gdb with all targets enabled on Mac OSX Mojave (10.14) using Homebrew (2.0.0).
I've tried:
brew install gdb --enable-targets=all
and
brew install gdb --with-all-targets
and receive Error: invalid option: --enable-targets=all and Error: invalid option: --with-all-targets
brew info gdb returns:
gdb: stable 8.2.1 (bottled), HEAD
GNU debugger
https://www.gnu.org/software/gdb/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gdb.rb
==> Dependencies
Build: pkg-config ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:
https://sourceware.org/gdb/wiki/BuildingOnDarwin
On 10.12 (Sierra) or later with SIP, you need to run this:
echo "set startup-with-shell off" >> ~/.gdbinit
==> Analytics
install: 13,521 (30 days), 42,502 (90 days), 153,991 (365 days)
install_on_request: 12,161 (30 days), 37,200 (90 days), 132,057 (365 days)
build_error: 0 (30 days)
Please note that none of the options are listed in the info that show in the gdb.rb link. What am I missing here?
Other options, like --disable-debug do not work either. If I remove all options, the install works fine.

Just figured it out. I created a modified version of the formula .rb file in my /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gdbCustom.rb and added the missing build options. I based it on this formula: https://raw.githubusercontent.com/Homebrew/homebrew-core/9ec9fb27a33698fc7636afce5c1c16787e9ce3f3/Formula/gdb.rb
Yes, I'm a newbie to Homebrew, but have a better understanding of how formulas work now. In case it helps others, see below final .rb. After adding the file to the above homebrew-core/Formula directory, run brew install gdbCustom --with-all-targets. The make takes several minutes, so be patient.
class Gdbcustom < Formula
desc "GNU debugger"
homepage "https://www.gnu.org/software/gdb/"
head "https://sourceware.org/git/binutils-gdb.git"
stable do
url "https://ftp.gnu.org/gnu/gdb/gdb-8.2.1.tar.xz"
mirror "https://ftpmirror.gnu.org/gdb/gdb-8.2.1.tar.xz"
sha256 "0a6a432907a03c5c8eaad3c3cffd50c00a40c3a5e3c4039440624bae703f2202"
# Fix build with all targets. Remove for 8.3
# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=0c0a40e0abb9f1a584330a1911ad06b3686e5361
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/d457e55/gdb/all-targets.diff"
sha256 "1cb8a1b8c4b4833212e16ba8cfbe620843aba0cba0f5111c2728c3314e10d8fd"
end
# Fix debugging of executables of Xcode 10 and later
# created for 10.14 and newer versions of macOS. Remove for 8.3
# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fc7b364aba41819a5d74ae0ac69f050af282d057
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/d457e55/gdb/mojave.diff"
sha256 "6264c71b57a0d5d4aed11430d352b03639370b7d36a5b520e189a6a1f105e383"
end
end
bottle do
sha256 "01b06c2983503c78bc346b5f5e2c2bdccbc41d6f5ca759542eef712bf123ca30" => :mojave
sha256 "9824d06b8d0d44e725a1d29f6631828b3b43abb1952c883e9fad559b6a816c04" => :high_sierra
sha256 "cf7371e9f6257d1a7dee80239d05917e424e5bb3e7577bd93f0e139fe5174198" => :sierra
end
# Owen: deprecated_option "with-brewed-python" => "with-python"
# Owen: deprecated_option "with-guile" => "with-guile#2.0"
option "with-python", "Use the Homebrew version of Python; by default system Python is used"
option "with-version-suffix", "Add a version suffix to program"
option "with-all-targets", "Build with support for all targets"
depends_on "pkg-config" => :build
# Owen: depends_on "python" => :optional
# Owen: depends_on "guile#2.0" => :optional
fails_with :clang do
build 800
cause <<~EOS
probe.c:63:28: error: default initialization of an object of const type
'const any_static_probe_ops' without a user-provided default constructor
EOS
end
fails_with :clang do
build 600
cause <<~EOS
clang: error: unable to execute command: Segmentation fault: 11
Test done on: Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
EOS
end
def install
args = %W[
--prefix=#{prefix}
--disable-debug
--disable-dependency-tracking
--enable-targets=all
--with-python=/usr
--disable-binutils
]
# Owen: args << "--with-guile" if build.with? "guile#2.0"
# Owen: args << "--enable-targets=all" if build.with? "all-targets"
if build.with? "python"
args << "--with-python=#{HOMEBREW_PREFIX}"
else
args << "--with-python=/usr"
end
if build.with? "version-suffix"
args << "--program-suffix=-#{version.to_s.slice(/^\d/)}"
end
system "./configure", *args
system "make"
# Don't install bfd or opcodes, as they are provided by binutils
# Owen: inreplace ["bfd/Makefile", "opcodes/Makefile"], /^install:/, "dontinstall:"
# Owen: system "make", "install"
system "make", "install-gdb"
end
def caveats; <<~EOS
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:
https://sourceware.org/gdb/wiki/BuildingOnDarwin
On 10.12 (Sierra) or later with SIP, you need to run this:
echo "set startup-with-shell off" >> ~/.gdbinit
EOS
end
test do
system bin/"gdb", bin/"gdb", "-configuration"
end
end

Related

Homebrew: How to install an old version of a formula which uses a bottle?

I'd like to use an older version of poppler which is needed in some program for inline PDF display. I can't use the newest due to incompatibility with the program.
I already managed to find out that to install poppler with the option --with-qt I need an older version of the poppler.rb formula. I got this version from github homebrew-core tap and I think it should be working. So far so good. Now in case I try to install this formula --with-qt I get the message that qt is outdated, which is due to the fact that the newest homebrew qt can't be installed on my OS anymore.
Therefore I'd need to install an old version of qt too. Hence I also got the older formula for qt-5.11.2 from github, modified the formula to be qt#5112 instead just qt and tried to install it, but I always get the message that this #5112formula is trying to download some bottle from
https://homebrew.bintray.com/bottles/qt#51122-5.11.2.el_capitan.bottle.tar.gz
which doesn't exist because its called just https://homebrew.bintray.com/bottles/qt-5.11.2....... Does anyone know how to resolve this? I.e.: how to rename some bottle? Or the formula for qt-5.11.2 from qt to qt#5112?
Or is there a better way to hack this brew formula?
I'd really apprechiate some useful inputs. Thanks!
qt#5112.rb formula I am trying to install (modified from here for #5112):
# Patches for Qt must be at the very least submitted to Qt's Gerrit codereview
# rather than their bug-report Jira. The latter is rarely reviewed by Qt.
class QtAT5112 < Formula
desc "Cross-platform application and UI framework"
homepage "https://www.qt.io/"
url "https://download.qt.io/official_releases/qt/5.11/5.11.2/single/qt-everywhere-src-5.11.2.tar.xz"
mirror "https://qt.mirror.constant.com/archive/qt/5.11/5.11.2/single/qt-everywhere-src-5.11.2.tar.xz"
mirror "https://ftp.osuosl.org/pub/blfs/conglomeration/qt5/qt-everywhere-src-5.11.2.tar.xz"
sha256 "c6104b840b6caee596fa9a35bc5f57f67ed5a99d6a36497b6fe66f990a53ca81"
head "https://code.qt.io/qt/qt5.git", :branch => "5.12", :shallow => false
bottle do
sha256 "8c77b5762267b127cc31346ac4da805bbfd59e0180d90e1e8b77fb463e929d60" => :mojave
sha256 "096d8894b25b0fdec9b77150704491993872a7848397a04870627534fb95c9e3" => :high_sierra
sha256 "0464be51d0eb0a45de4a1d1c6200e1d9768eec5e9737050755497a4f4de66a08" => :sierra
sha256 "22e9abc0b47541bb03b2da7f6a19c5d7640ea2314322564551adc3d22305806e" => :el_capitan
end
keg_only "Qt 5 has CMake issues when linked"
option "with-examples", "Build examples"
option "without-proprietary-codecs", "Don't build with proprietary codecs (e.g. mp3)"
deprecated_option "with-mysql" => "with-mysql-client"
depends_on "pkg-config" => :build
depends_on :xcode => :build
depends_on "mysql-client" => :optional
depends_on "postgresql" => :optional
# Restore `.pc` files for framework-based build of Qt 5 on macOS, partially
# reverting <https://codereview.qt-project.org/#/c/140954/>
# Core formulae known to fail without this patch (as of 2016-10-15):
# * gnuplot (with `--with-qt` option)
# * mkvtoolnix (with `--with-qt` option, silent build failure)
# * poppler (with `--with-qt` option)
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/e8fe6567/qt5/restore-pc-files.patch"
sha256 "48ff18be2f4050de7288bddbae7f47e949512ac4bcd126c2f504be2ac701158b"
end
# Chromium build failures with Xcode 10, fixed upstream:
# https://bugs.chromium.org/p/chromium/issues/detail?id=840251
# https://bugs.chromium.org/p/chromium/issues/detail?id=849689
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/962f0f/qt/xcode10.diff"
sha256 "c064398411c69f2e1c516c0cd49fcd0755bc29bb19e65c5694c6d726c43389a6"
end
def install
args = %W[
-verbose
-prefix #{prefix}
-release
-opensource -confirm-license
-system-zlib
-qt-libpng
-qt-libjpeg
-qt-freetype
-qt-pcre
-nomake tests
-no-rpath
-pkg-config
-dbus-runtime
]
args << "-nomake" << "examples" if build.without? "examples"
if build.with? "mysql-client"
args << "-plugin-sql-mysql"
(buildpath/"brew_shim/mysql_config").write <<~EOS
#!/bin/sh
if [ x"$1" = x"--libs" ]; then
mysql_config --libs | sed "s/-lssl -lcrypto//"
else
exec mysql_config "$#"
fi
EOS
chmod 0755, "brew_shim/mysql_config"
args << "-mysql_config" << buildpath/"brew_shim/mysql_config"
end
args << "-plugin-sql-psql" if build.with? "postgresql"
args << "-proprietary-codecs" if build.with? "proprietary-codecs"
system "./configure", *args
system "make"
ENV.deparallelize
system "make", "install"
# Some config scripts will only find Qt in a "Frameworks" folder
frameworks.install_symlink Dir["#{lib}/*.framework"]
# The pkg-config files installed suggest that headers can be found in the
# `include` directory. Make this so by creating symlinks from `include` to
# the Frameworks' Headers folders.
Pathname.glob("#{lib}/*.framework/Headers") do |path|
include.install_symlink path => path.parent.basename(".framework")
end
# Move `*.app` bundles into `libexec` to expose them to `brew linkapps` and
# because we don't like having them in `bin`.
# (Note: This move breaks invocation of Assistant via the Help menu
# of both Designer and Linguist as that relies on Assistant being in `bin`.)
libexec.mkpath
Pathname.glob("#{bin}/*.app") { |app| mv app, libexec }
end
def caveats; <<~EOS
We agreed to the Qt open source license for you.
If this is unacceptable you should uninstall.
EOS
end
test do
(testpath/"hello.pro").write <<~EOS
QT += core
QT -= gui
TARGET = hello
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
EOS
(testpath/"main.cpp").write <<~EOS
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Hello World!";
return 0;
}
EOS
system bin/"qmake", testpath/"hello.pro"
system "make"
assert_predicate testpath/"hello", :exist?
assert_predicate testpath/"main.o", :exist?
system "./hello"
end
end
You misunderstood one things. qt and qt#5112 are two different names. They are recognized as two different packages by Homebrew.
But the old proppler depends_on "qt", not qt#5112. You have to rename the formula file qt#5112 back to qt.

The compilation of ocamlfind failed at "install -m 0755 ocaml-stub

I'm new to OCaml and I'm trying to install cohttp. After a failure because I hadn't accepted the Xcode license agreement (OS X Sierra 10.12.6) I get an error while the package manager (opam) is trying to install a sub-dependency, ocamlfind.
=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 🐫
[ERROR] The compilation of ocamlfind failed at "install -m 0755 ocaml-stub /Users/greg/.opam/system/bin/ocaml".
Processing 1/27: [ocamlfind: rm]
#=== ERROR while installing ocamlfind.1.7.3-1 =================================#
# opam-version 1.2.2
# os darwin
# command install -m 0755 ocaml-stub /Users/greg/.opam/system/bin/ocaml
# path /Users/greg/.opam/system/build/ocamlfind.1.7.3-1
# compiler system (4.05.0)
# exit-code 127
# env-file /Users/greg/.opam/system/build/ocamlfind.1.7.3-1/ocamlfind-93888-487c34.env
# stdout-file /Users/greg/.opam/system/build/ocamlfind.1.7.3-1/ocamlfind-93888-487c34.out
# stderr-file /Users/greg/.opam/system/build/ocamlfind.1.7.3-1/ocamlfind-93888-487c34.err
The log files are empty. The env file has this (lightly edited):
PATH=/Users/greg/.opam/system/bin:/usr/local/google-cloud-sdk/bin:/Users/greg/.nvm/versions/node/v6.5.0/bin::/opt/chefdk/bin:/usr/local/mysql/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/greg/.chefdk/gem/ruby/2.1.0/bin
OCAML_TOPLEVEL_PATH=/Users/greg/.opam/system/lib/toplevel
PERL5LIB=/Users/greg/.opam/system/lib/perl5:
MANPATH=/Users/greg/.opam/system/man:/Users/greg/.nvm/versions/node/v6.5.0/share/man:/usr/local/mysql/man:/usr/local/share/man:/usr/share/man:/Applications/Xcode.app/Contents/Developer/usr/share/man:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/share/man
OPAMSWITCH=system
OPAMUTF8MSGS=1
CAML_LD_LIBRARY_PATH=/Users/greg/.opam/system/lib/stublibs:/usr/local/lib/ocaml/stublibs
TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/fq/9ggcftcj1lsb150mldyjn5sh0000gn/T/
NVM_PATH=/Users/greg/.nvm/versions/node/v6.5.0/lib/node
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.jNLKBcDJTX/Render
TERM_PROGRAM_VERSION=388.1.1
TERM_SESSION_ID=E845D49D-9C60-4CEA-8777-19F521ED83A1
NVM_DIR=/Users/greg/.nvm
USER=greg
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.0CA6ZcRBJQ/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x52
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
PWD=/Users/greg/dev/ocaml
EDITOR=emacs
LANG=en_CA.UTF-8
NODE_PATH=./src
XPC_FLAGS=0x0
NODE_ENV=development
XPC_SERVICE_NAME=0
HOME=/Users/greg
SHLVL=1
LOGNAME=greg
NVM_BIN=/Users/greg/.nvm/versions/node/v6.5.0/bin
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
PROMPT_COMMAND=set_tab_title
_=/usr/local/bin/opam
OPAM_PACKAGE_VERSION=1.7.3-1
OPAM_PACKAGE_NAME=ocamlfind
MAKELEVEL=
MAKEFLAGS=
I don't have a lot to go on to debug this. Any suggestions on where to go from here?
This github issue for opam led me to a solution that worked for me: https://github.com/ocaml/opam-repository/issues/10064
The solution to the github issue was that the user had the local directory, ., in their $PATH which led to the wrong install command being run. This wasn't my problem, but I had an extra : in my path.
/Users/greg/.nvm/versions/node/v6.5.0/bin::/opt/chefdk/bin:/usr/local/mysql/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
According to the comment below having two colons in a row in the path string will add the empty string as part of the path which is interpreted as the current directory.
Removing the extra colon allows the install of ocamlfind to succeed.

How to make cmake from brew install the default cmake - Mac OS

On the terminal, I've
$ cmake --version
cmake version 3.4.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ which cmake
/usr/local/bin/cmake
But when I upgraded the cmake using brew:
$ brew upgrade cmake
Error: cmake 3.8.2 already installed
$ brew edit cmake
How to make cmake from brew install the default cmake ?
My formula file from brew edit cmake:
class Cmake < Formula
desc "Cross-platform make"
homepage "https://www.cmake.org/"
url "https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz"
sha256 "da3072794eb4c09f2d782fcee043847b99bb4cf8d4573978d9b2024214d6e92d"
head "https://cmake.org/cmake.git"
bottle do
cellar :any_skip_relocation
sha256 "2bbeaf0866446737719aca74468290101b0c502065a02ad6e286f69fc0e69c77" => :sierra
sha256 "74ecc634b8cc6facc828cc434ec16383681736c3c2fc42dd144f78e88bd34842" => :el_capitan
sha256 "9b53dec241998124c67645be81c8e85db097404115e466cf409caf43add783ae" => :yosemite
end
devel do
url "https://cmake.org/files/v3.9/cmake-3.9.0-rc5.tar.gz"
sha256 "3ef250f93f1887d99c567542e987938bf1cb49af06275e0081b547765e03e6ac"
end
option "without-docs", "Don't build man pages"
option "with-completion", "Install Bash completion (Has potential problems with system bash)"
depends_on "sphinx-doc" => :build if build.with? "docs"
# The `with-qt` GUI option was removed due to circular dependencies if
# CMake is built with Qt support and Qt is built with MySQL support as MySQL uses CMake.
# For the GUI application please instead use `brew cask install cmake`.
def install
args = %W[
--prefix=#{prefix}
--no-system-libs
--parallel=#{ENV.make_jobs}
--datadir=/share/cmake
--docdir=/share/doc/cmake
--mandir=/share/man
--system-zlib
--system-bzip2
--system-curl
]
if build.with? "docs"
# There is an existing issue around macOS & Python locale setting
# See https://bugs.python.org/issue18378#msg215215 for explanation
ENV["LC_ALL"] = "en_US.UTF-8"
args << "--sphinx-man" << "--sphinx-build=#{Formula["sphinx-doc"].opt_bin}/sphinx-build"
end
system "./bootstrap", *args
system "make"
system "make", "install"
if build.with? "completion"
cd "Auxiliary/bash-completion/" do
bash_completion.install "ctest", "cmake", "cpack"
end
end
elisp.install "Auxiliary/cmake-mode.el"
end
test do
(testpath/"CMakeLists.txt").write("find_package(Ruby)")
system bin/"cmake", "."
end
end
Using brew link would work but before you have to purge the /usr/local/bin/cmake and /usr/local/bin/ccmake:
sudo rm /usr/local/bin/cmake
sudo rm /usr/local/bin/ccmake
brew link cmake
Or let brew automatically purge them:
brew link --overwrite cmake

What should I override in cargo for the openssl-rust crate to build? [duplicate]

I tried to install the Iron framework for Rust on Mac OS X 10.11.2, but it failed when I run cargo build or cargo run on compiling openssl's stuff:
failed to run custom build command for `openssl-sys-extras v0.7.4`
Process didn't exit successfully: `/xxx/rust/hello/target/debug/build/openssl-sys-extras-413d6c73b37a590d/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("x86_64-apple-darwin")
debug=true opt-level=0
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-apple-darwin = None
CC_x86_64_apple_darwin = None
HOST_CC = None
CC = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-apple-darwin = None
CFLAGS_x86_64_apple_darwin = None
HOST_CFLAGS = None
CFLAGS = None
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-m64" "-fPIC" "-o" "/xxx/rust/hello/target/debug/build/openssl-sys-extras-413d6c73b37a590d/out/src/openssl_shim.o" "-c" "src/openssl_shim.c"
ExitStatus(Code(1))
command did not execute successfully, got: exit code: 1
--- stderr
src/openssl_shim.c:1:10: fatal error: 'openssl/hmac.h' file not found
#include <openssl/hmac.h>
^
1 error generated.
thread '<main>' panicked at 'explicit panic', /xxx/.cargo/registry/src/github.com-0a35038f75765ae4/gcc-0.3.21/src/lib.rs:772
openssl version seems OK:
$ openssl version
OpenSSL 0.9.8zg 14 July 2015
I don't know what I have to do in order to make this installation work and give Iron a try.
As of rust-openssl version 0.8, Homebrew-installed OpenSSL libraries will be automatically detected by the crate, there is no need to set extra environment variables.
If you need to support a version prior to that or choose to not use Homebrew, read on.
This is a known issue (also this and this), but not one that the crate can fix.
The quick solution is to install OpenSSL with Homebrew and then explicitly point to the directories where OpenSSL is found by setting the OPENSSL_INCLUDE_DIR and OPENSSL_LIB_DIR environment variables:
OPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2e/include \
OPENSSL_LIB_DIR=/usr/local/Cellar/openssl/1.0.2e/lib \
cargo build
If you've already done one cargo build, you will need to run cargo clean first to clear our some stale cached information.
If you don't want to set this for every shell you open, add it to your shell initialization files (like ~/.bash_profile). You can make it a bit less brittle by not hard-coding the version number:
export OPENSSL_INCLUDE_DIR=$(brew --prefix openssl)/include
export OPENSSL_LIB_DIR=$(brew --prefix openssl)/lib
If you don't want to use Homebrew, follow the same process but using the appropriate path to your copy of OpenSSL.
The longer reason is well described by andrewtj:
OpenSSL doesn't have a stable ABI so for compatibility purposes Apple have maintained a fork that's compatible with one of the earlier ABIs. They deprecated OpenSSL in 10.7 and finally dropped the headers in 10.11 to push OS X app developers toward bundling their own OpenSSL or using their frameworks. The dylibs have been left around so apps that haven't been updated don't break. You can still link against them but you're opening yourself up to odd compatibility issues by doing so (unless you grab the headers from an earlier OS X release).
With Brew use like this:
brew install openssl
export OPENSSL_INCLUDE_DIR=`brew --prefix openssl`/include
export OPENSSL_LIB_DIR=`brew --prefix openssl`/lib
cargo clean
cargo build
If you have homebrew's openssl installed just add the following to your Cargo.toml:
[target.x86_64-apple-darwin.openssl-sys]
rustc-link-search = [ "/usr/local/opt/openssl/lib" ]
rustc-link-lib = [ "ssl", "crypto" ]
include = [ "/usr/local/opt/openssl/include" ]
and then cargo clean && cargo build. No breaking OS X by introducing an incompatible openssl into the library load paths, and no forgetting to set/unset environment variables when you want to build (or polluting your shell env when not working on Rust stuff). All in all a much happier and less infuriating approach.
I can't add this answer to my own question where it belongs (because it depends on homebrew), because Shepmaster decided it should be closed but I'll answer here and link to that question.
https://stackoverflow.com/a/39380733/1317564's answer for MacPorts:
sudo port install openssl
export OPENSSL_INCLUDE_DIR=/opt/local/include
export OPENSSL_LIB_DIR=/opt/local/lib
cargo clean
cargo build

OpenSSL crate fails compilation on Mac OS X 10.11

I tried to install the Iron framework for Rust on Mac OS X 10.11.2, but it failed when I run cargo build or cargo run on compiling openssl's stuff:
failed to run custom build command for `openssl-sys-extras v0.7.4`
Process didn't exit successfully: `/xxx/rust/hello/target/debug/build/openssl-sys-extras-413d6c73b37a590d/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("x86_64-apple-darwin")
debug=true opt-level=0
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-apple-darwin = None
CC_x86_64_apple_darwin = None
HOST_CC = None
CC = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-apple-darwin = None
CFLAGS_x86_64_apple_darwin = None
HOST_CFLAGS = None
CFLAGS = None
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-m64" "-fPIC" "-o" "/xxx/rust/hello/target/debug/build/openssl-sys-extras-413d6c73b37a590d/out/src/openssl_shim.o" "-c" "src/openssl_shim.c"
ExitStatus(Code(1))
command did not execute successfully, got: exit code: 1
--- stderr
src/openssl_shim.c:1:10: fatal error: 'openssl/hmac.h' file not found
#include <openssl/hmac.h>
^
1 error generated.
thread '<main>' panicked at 'explicit panic', /xxx/.cargo/registry/src/github.com-0a35038f75765ae4/gcc-0.3.21/src/lib.rs:772
openssl version seems OK:
$ openssl version
OpenSSL 0.9.8zg 14 July 2015
I don't know what I have to do in order to make this installation work and give Iron a try.
As of rust-openssl version 0.8, Homebrew-installed OpenSSL libraries will be automatically detected by the crate, there is no need to set extra environment variables.
If you need to support a version prior to that or choose to not use Homebrew, read on.
This is a known issue (also this and this), but not one that the crate can fix.
The quick solution is to install OpenSSL with Homebrew and then explicitly point to the directories where OpenSSL is found by setting the OPENSSL_INCLUDE_DIR and OPENSSL_LIB_DIR environment variables:
OPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2e/include \
OPENSSL_LIB_DIR=/usr/local/Cellar/openssl/1.0.2e/lib \
cargo build
If you've already done one cargo build, you will need to run cargo clean first to clear our some stale cached information.
If you don't want to set this for every shell you open, add it to your shell initialization files (like ~/.bash_profile). You can make it a bit less brittle by not hard-coding the version number:
export OPENSSL_INCLUDE_DIR=$(brew --prefix openssl)/include
export OPENSSL_LIB_DIR=$(brew --prefix openssl)/lib
If you don't want to use Homebrew, follow the same process but using the appropriate path to your copy of OpenSSL.
The longer reason is well described by andrewtj:
OpenSSL doesn't have a stable ABI so for compatibility purposes Apple have maintained a fork that's compatible with one of the earlier ABIs. They deprecated OpenSSL in 10.7 and finally dropped the headers in 10.11 to push OS X app developers toward bundling their own OpenSSL or using their frameworks. The dylibs have been left around so apps that haven't been updated don't break. You can still link against them but you're opening yourself up to odd compatibility issues by doing so (unless you grab the headers from an earlier OS X release).
With Brew use like this:
brew install openssl
export OPENSSL_INCLUDE_DIR=`brew --prefix openssl`/include
export OPENSSL_LIB_DIR=`brew --prefix openssl`/lib
cargo clean
cargo build
If you have homebrew's openssl installed just add the following to your Cargo.toml:
[target.x86_64-apple-darwin.openssl-sys]
rustc-link-search = [ "/usr/local/opt/openssl/lib" ]
rustc-link-lib = [ "ssl", "crypto" ]
include = [ "/usr/local/opt/openssl/include" ]
and then cargo clean && cargo build. No breaking OS X by introducing an incompatible openssl into the library load paths, and no forgetting to set/unset environment variables when you want to build (or polluting your shell env when not working on Rust stuff). All in all a much happier and less infuriating approach.
I can't add this answer to my own question where it belongs (because it depends on homebrew), because Shepmaster decided it should be closed but I'll answer here and link to that question.
https://stackoverflow.com/a/39380733/1317564's answer for MacPorts:
sudo port install openssl
export OPENSSL_INCLUDE_DIR=/opt/local/include
export OPENSSL_LIB_DIR=/opt/local/lib
cargo clean
cargo build

Resources