Ruby-build: OpenSSL fails to build on Apple DTK

Created on 16 Jul 2020  路  7Comments  路  Source: rbenv/ruby-build

The latest version of OpenSSL is missing the proper configurations to build on the Apple DTK, ultimately making ruby-build fail when compiling it.

A patch for this has already been accepted by OpenSSL: https://github.com/openssl/openssl/pull/12369

Most helpful comment

On my Apple Silicon, I can build it with the following changes.

  • Patch
diff --git a/bin/ruby-build b/bin/ruby-build
index 70c1978..c1a7bec 100755
--- a/bin/ruby-build
+++ b/bin/ruby-build
@@ -1095,13 +1095,22 @@ build_package_mac_openssl() {

   # Hint OpenSSL that we prefer a 64-bit build.
   export KERNEL_BITS="64"
-  OPENSSL_CONFIGURE="${OPENSSL_CONFIGURE:-./config}"
+  OPENSSL_CONFIGURE="${OPENSSL_CONFIGURE:-./Configure}"

   local nokerberos
   [[ "$1" != openssl-1.0.* ]] || nokerberos=1

+  # Apply https://github.com/openssl/openssl/pull/12369/commits/4907cf01f63cc966a40d67eb2e030c4d8eb1d528
+  curl https://github.com/openssl/openssl/commit/4907cf01f63cc966a40d67eb2e030c4d8eb1d528.diff | git apply
+
+  if [[ `sysctl machdep.cpu.brand_string` =~ 'Apple processor' ]] ; then
+      ARCH=darwin64-arm64-cc
+  else
+      ARCH=darwin64-x86_64-cc
+  fi
+
   # Compile a shared lib with zlib dynamically linked.
-  package_option openssl configure --openssldir="$OPENSSLDIR" zlib-dynamic no-ssl3 shared ${nokerberos:+no-ssl2 no-krb5}
+  package_option openssl configure --openssldir="$OPENSSLDIR" "$ARCH" zlib-dynamic no-ssl3 shared ${nokerberos:+no-ssl2 no-krb5}

   # Default MAKE_OPTS are -j 2 which can confuse the build. Thankfully, make
   # gives precedence to the last -j option, so we can override that.
  • Command
$ CFLAGS='-DUSE_FFI_CLOSURE_ALLOC=1' rbenv install 2.7.1 --verbose

To avoid build error in fiddle gem, it requires CFLAGS like above.

All 7 comments

@stack Thanks for your report. I think We need to wait a new release of OpenSSL for Apple Silicon.

The patch is really just adding a configuration file specifically for Apple Silicon. It isn't a source code change. I bring it up mostly because who knows when OpenSSL will actually cut releases.

In ruby-build, ./config script to configuration has been used.
https://github.com/rbenv/ruby-build/blob/01b07a267b98dfb532a852572444cbd6481746e9/bin/ruby-build#L1098

Unfortunately, that script is broken on Apple Silicon.

% ./config
Operating system: i686-apple-darwinDarwin Kernel Version 20.0.0: Thu Jul 30 22:49:27 PDT 2020; root:xnu-7195.0.0.141.5~1/RELEASE_ARM64_T8020
Configuring OpenSSL version 1.1.1g (0x1010107fL) for darwin-i386-cc
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************

The script configured for i386 CPU.

Rosetta2 might works, at least when built for x86_64.

It is possible to build openssl through Homebrew, so I hope it help you.
https://github.com/Homebrew/homebrew-core/pull/57124/files

On my Apple Silicon, I can build it with the following changes.

  • Patch
diff --git a/bin/ruby-build b/bin/ruby-build
index 70c1978..c1a7bec 100755
--- a/bin/ruby-build
+++ b/bin/ruby-build
@@ -1095,13 +1095,22 @@ build_package_mac_openssl() {

   # Hint OpenSSL that we prefer a 64-bit build.
   export KERNEL_BITS="64"
-  OPENSSL_CONFIGURE="${OPENSSL_CONFIGURE:-./config}"
+  OPENSSL_CONFIGURE="${OPENSSL_CONFIGURE:-./Configure}"

   local nokerberos
   [[ "$1" != openssl-1.0.* ]] || nokerberos=1

+  # Apply https://github.com/openssl/openssl/pull/12369/commits/4907cf01f63cc966a40d67eb2e030c4d8eb1d528
+  curl https://github.com/openssl/openssl/commit/4907cf01f63cc966a40d67eb2e030c4d8eb1d528.diff | git apply
+
+  if [[ `sysctl machdep.cpu.brand_string` =~ 'Apple processor' ]] ; then
+      ARCH=darwin64-arm64-cc
+  else
+      ARCH=darwin64-x86_64-cc
+  fi
+
   # Compile a shared lib with zlib dynamically linked.
-  package_option openssl configure --openssldir="$OPENSSLDIR" zlib-dynamic no-ssl3 shared ${nokerberos:+no-ssl2 no-krb5}
+  package_option openssl configure --openssldir="$OPENSSLDIR" "$ARCH" zlib-dynamic no-ssl3 shared ${nokerberos:+no-ssl2 no-krb5}

   # Default MAKE_OPTS are -j 2 which can confuse the build. Thankfully, make
   # gives precedence to the last -j option, so we can override that.
  • Command
$ CFLAGS='-DUSE_FFI_CLOSURE_ALLOC=1' rbenv install 2.7.1 --verbose

To avoid build error in fiddle gem, it requires CFLAGS like above.

@Watson1978 do you have any further details on how one could apply that patch locally? Do I need to check out the source? Or can I just modify existing files on my machine?

If you apply the patch above, it might still work.

Was this page helpful?
0 / 5 - 0 ratings