Skip to content

Commit b30ccec

Browse files
committed
Really fix OSX nightlies
After rust-lang#3311 we're now correctly trying to link OpenSSL statically on OSX. Unfortunately though this is failing to complete on the builders. Turns out the way we install OpenSSL through Homebrew create "universal archives" which is essentially an archive with both i686 and x86_64 object files, but separated. The linker takes care of this just fine but rustc currently chokes on it, unable to include the library statically into the compiler. To work around this we prepare our own mini install of OpenSSL by copying relevant bits into a local directory (like we do on Linux). As part of this we use the `lipo` tool, which is used to manage these fat archives, to disassemble the archive and only extract the relevant architecture. This should make a pre-installation step which both extracts the information and configures Cargo to use it. This should also fix the errors we're seeing on Travis I believe.
1 parent b2fd918 commit b30ccec

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

Makefile.in

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,20 @@ SETARCH_i686-unknown-linux-gnu := setarch i386
231231
OPENSSL_CFLAGS_i686-unknown-linux-gnu := -m32
232232
OPENSSL_CFLAGS_i686-unknown-linux-musl := -m32
233233

234+
LIPO_FAMILY_i686-apple-darwin := i386
235+
LIPO_FAMILY_x86_64-apple-darwin := x86_64
236+
234237
define BUILD_OPENSSL
235238

236239
ifdef CFG_ENABLE_NIGHTLY
240+
237241
cargo-$(1): export OPENSSL_STATIC := 1
238242
test-unit-$(1): export OPENSSL_STATIC := 1
239-
endif
240243

241-
ifdef OPENSSL_OS_$(1)
242-
ifdef CFG_ENABLE_NIGHTLY
243244
OPENSSL_INSTALL_$(1) := $$(CFG_BUILD_DIR)/target/openssl/$(1)-install
244245

246+
ifdef OPENSSL_OS_$(1)
247+
245248
target/openssl/$(1).stamp: target/openssl/openssl-$$(OPENSSL_VERS).tar.gz \
246249
| target/openssl/
247250
mkdir -p target/openssl/$(1)
@@ -261,12 +264,39 @@ test-unit-$(1): export OPENSSL_DIR := $$(OPENSSL_INSTALL_$(1))
261264

262265
# build libz statically into the cargo we're producing
263266
cargo-$(1): export LIBZ_SYS_STATIC := 1
264-
else
267+
268+
else ifdef LIPO_FAMILY_$(1)
269+
265270
target/openssl/$(1).stamp:
271+
@echo installing from `brew --prefix openssl`
272+
@rm -rf $$(OPENSSL_INSTALL_$(1))
273+
mkdir -p $$(OPENSSL_INSTALL_$(1))/lib
274+
cp -r `brew --prefix openssl`/include $$(OPENSSL_INSTALL_$(1))/include
275+
cp -r `brew --prefix openssl`/lib/pkgconfig $$(OPENSSL_INSTALL_$(1))/lib/pkgconfig
276+
lipo -output $$(OPENSSL_INSTALL_$(1))/lib/libssl.a \
277+
-extract_family $$(LIPO_FAMILY_$(1)) \
278+
`brew --prefix openssl`/lib/libssl.a || \
279+
cp `brew --prefix openssl`/lib/libssl.a \
280+
$$(OPENSSL_INSTALL_$(1))/lib/libssl.a
281+
lipo -output $$(OPENSSL_INSTALL_$(1))/lib/libcrypto.a \
282+
-extract_family $$(LIPO_FAMILY_$(1)) \
283+
`brew --prefix openssl`/lib/libcrypto.a || \
284+
cp `brew --prefix openssl`/lib/libcrypto.a \
285+
$$(OPENSSL_INSTALL_$(1))/lib/libcrypto.a
286+
touch $$@
287+
288+
cargo-$(1): export OPENSSL_DIR := $$(OPENSSL_INSTALL_$(1))
289+
test-unit-$(1): export OPENSSL_DIR := $$(OPENSSL_INSTALL_$(1))
290+
291+
else # !OPENSSL_OS_$(1) && !OSX
292+
target/openssl/$(1).stamp:
293+
266294
endif
267-
else
295+
296+
else # !CFG_ENABLE_NIGHTLY
268297
target/openssl/$(1).stamp:
269298
endif
299+
270300
endef
271301

272302
$(foreach target,$(CFG_TARGET),$(eval $(call BUILD_OPENSSL,$(target))))

0 commit comments

Comments
 (0)