Simplify build on macOS (#35570)
authorCédric Luthi <cedric.luthi@gmail.com>
Thu, 7 May 2020 09:12:29 +0000 (11:12 +0200)
committerGitHub <noreply@github.com>
Thu, 7 May 2020 09:12:29 +0000 (11:12 +0200)
* Check for OpenSSL (and pkg-config) in the check_prereqs() function
* Simplify OpenSSL installation instructions
* Automatically pick the OpenSSL version installed by Homebrew by exporting the proper PKG_CONFIG_PATH environment variable
* Improve the error message if cmake can't find OpenSSL

The previous instructions were asking the user to add symbolic links inside  /usr/local/lib/ and /usr/local/lib/pkgconfig/ for OpenSSL related files. There is no need for a complicated setup with symbolic links when the PKG_CONFIG_PATH environment variable points to the right pkgconfig, which is now done in build-commons.sh.

Co-Authored-By: Jan Kotas <jkotas@microsoft.com>
Co-Authored-By: Jeremy Barton <jbarton@microsoft.com>
docs/workflow/building/coreclr/osx-instructions.md
docs/workflow/requirements/macos-requirements.md
eng/install-native-dependencies.sh
eng/native/build-commons.sh
eng/pipelines/common/global-build-job.yml
eng/pipelines/installer/jobs/base-job.yml
eng/pipelines/libraries/build-job.yml
src/libraries/Native/Unix/System.Security.Cryptography.Native/CMakeLists.txt

index ddcaeda..b8a168d 100644 (file)
@@ -23,9 +23,7 @@ git clone https://github.com/dotnet/runtime
 CMake
 -----
 
-CoreCLR has a dependency on CMake for the build. You can download it from [CMake downloads](http://www.cmake.org/download/).
-
-Alternatively, you can install CMake from [Homebrew](http://brew.sh/).
+CoreCLR has a dependency on CMake for the build. You can install it with [Homebrew](https://brew.sh/).
 
 ```sh
 brew install cmake
@@ -33,11 +31,10 @@ brew install cmake
 
 ICU
 ---
-ICU (International Components for Unicode) is also required to build and run. It can be obtained via [Homebrew](http://brew.sh/).
+ICU (International Components for Unicode) is also required to build and run. It can be obtained via [Homebrew](https://brew.sh/).
 
 ```sh
 brew install icu4c
-brew link --force icu4c
 ```
 
 Build the Runtime and System.Private.CoreLib
index 06d1fb0..82a6610 100644 (file)
@@ -23,47 +23,14 @@ Install the following packages:
 - cmake 3.15.5 or newer
 - autoconf
 - automake
+- icu4c
 - libtool
+- openssl 1.1
 - pkg-config
 - python3
-- icu4c
 
 The lines to install all the packages above using Homebrew.
 
 ```
-brew install cmake autoconf automake libtool pkg-config python3 icu4c
-brew link --force icu4c
-```
-
-OpenSSL
--------
-
-To build the libraries on macOS, you must install and configure links for OpenSSL 1.1.
-
-```sh
-brew install openssl
-
-# You might need to "link" pkg-config:
-brew link pkg-config
-
-# We need to make the runtime libraries discoverable, as well as make
-# pkg-config be able to find the headers and current ABI version.
-#
-# Ensure the paths we will need exist
-mkdir -p /usr/local/lib/pkgconfig
-
-# The rest of these instructions assume a default Homebrew path of
-# `/usr/local/opt/<module>`, with `brew --prefix` returning `/usr/local`
-# and `brew --prefix openssl` returning `/usr/local/opt/openssl@1.1`.
-# In this case, `brew info openssl` shows:
-# `openssl@1.1: stable 1.1.1d (bottled) [keg-only]`.
-
-# Runtime dependencies
-ln -s /usr/local/opt/openssl\@1.1/lib/libcrypto.1.1.dylib /usr/local/lib/
-ln -s /usr/local/opt/openssl\@1.1/lib/libssl.1.1.dylib /usr/local/lib/
-
-# Compile-time dependencies (for pkg-config)
-ln -s /usr/local/opt/openssl\@1.1/lib/pkgconfig/libcrypto.pc /usr/local/lib/pkgconfig/
-ln -s /usr/local/opt/openssl\@1.1/lib/pkgconfig/libssl.pc /usr/local/lib/pkgconfig/
-ln -s /usr/local/opt/openssl\@1.1/lib/pkgconfig/openssl.pc /usr/local/lib/pkgconfig/
+brew install cmake autoconf automake icu4c libtool openssl@1.1 pkg-config python3
 ```
index 9670ae5..be15481 100644 (file)
@@ -15,11 +15,10 @@ elif [ "$1" = "OSX" ]; then
     if [ "$?" != "0" ]; then
         exit 1;
     fi
-    brew install icu4c openssl autoconf automake libtool pkg-config python3
+    brew install autoconf automake icu4c libtool openssl@1.1 pkg-config python3
     if [ "$?" != "0" ]; then
         exit 1;
     fi
-    brew link --force icu4c
     if [ "$?" != "0" ]; then
         exit 1;
     fi
@@ -29,7 +28,7 @@ elif [ "$1" = "tvOS" ]; then
     if [ "$?" != "0" ]; then
         exit 1;
     fi
-    brew install openssl autoconf automake libtool pkg-config python3
+    brew install autoconf automake libtool openssl@1.1 pkg-config python3
     if [ "$?" != "0" ]; then
         exit 1;
     fi
@@ -39,7 +38,7 @@ elif [ "$1" = "iOS" ]; then
     if [ "$?" != "0" ]; then
         exit 1;
     fi
-    brew install openssl autoconf automake libtool pkg-config python3
+    brew install autoconf automake libtool openssl@1.1 pkg-config python3
     if [ "$?" != "0" ]; then
         exit 1;
     fi
index ad9ed3c..27381c6 100755 (executable)
@@ -59,6 +59,19 @@ check_prereqs()
         echo "Please install CMake 3.14.2 or newer from http://www.cmake.org/download/ or https://apt.kitware.com and ensure it is on your path."; exit 1;
     fi
 
+    if [[ "$__HostOS" == "OSX" ]]; then
+        # Check presence of pkg-config on the path
+        command -v pkg-config 2>/dev/null || { echo >&2 "Please install pkg-config before running this script, see https://github.com/dotnet/runtime/blob/master/docs/workflow/requirements/macos-requirements.md"; exit 1; }
+
+        if ! pkg-config openssl ; then
+            # We export the proper PKG_CONFIG_PATH where openssl was installed by Homebrew
+            # It's important to _export_ it since build-commons.sh is sourced by other scripts such as build-native.sh
+            export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig
+            # We try again with the PKG_CONFIG_PATH in place, if pkg-config still can't find OpenSSL, exit with an error, cmake won't find OpenSSL either
+            pkg-config openssl || { echo >&2 "Please install openssl before running this script, see https://github.com/dotnet/runtime/blob/master/docs/workflow/requirements/macos-requirements.md"; exit 1; }
+        fi
+    fi
+
     if [[ "$__UseNinja" == 1 ]]; then
         command -v ninja 2>/dev/null || command -v ninja-build 2>/dev/null || { echo "Unable to locate ninja!"; exit 1; }
     fi
index 75d9678..e0f71a3 100644 (file)
@@ -25,19 +25,12 @@ jobs:
     variables: ${{ parameters.variables }}
 
     steps:
-    - ${{ if eq(parameters.osGroup, 'OSX') }}:
-      - script: |
-          $(setScriptToEchoAndFailOnNonZero) 
-          brew install pkgconfig icu4c openssl autoconf automake libtool pkg-config python3
-          brew link --force icu4c
-          ln -s /usr/local/opt/openssl/lib/pkgconfig/libcrypto.pc /usr/local/lib/pkgconfig/
-          ln -s /usr/local/opt/openssl/lib/pkgconfig/libssl.pc /usr/local/lib/pkgconfig/
-          ln -s /usr/local/opt/openssl/lib/pkgconfig/openssl.pc /usr/local/lib/pkgconfig/
-        displayName: Install Build Dependencies
-
     - template: /eng/pipelines/common/clone-checkout-bundle-step.yml
 
-    - ${{ if in(parameters.osGroup, 'OSX', 'iOS','tvOS') }}: 
+    - ${{ if in(parameters.osGroup, 'OSX', 'iOS', 'tvOS') }}:
+      - script: sh $(Build.SourcesDirectory)/eng/install-native-dependencies.sh ${{ parameters.osGroup }}
+        displayName: Install Build Dependencies
+
       - script: |
           du -sh $(Build.SourcesDirectory)/*
           df -h
index fd90c6e..413f9c7 100644 (file)
@@ -442,7 +442,10 @@ jobs:
         displayName: 'Libraries artifacts (AllConfigurations)'
         cleanUnpackFolder: false
 
-  - ${{ if in(parameters.osGroup, 'OSX', 'iOS','tvOS') }}: 
+  - ${{ if in(parameters.osGroup, 'OSX', 'iOS', 'tvOS') }}:
+    - script: sh $(Build.SourcesDirectory)/eng/install-native-dependencies.sh ${{ parameters.osGroup }}
+      displayName: Install Build Dependencies
+
     - script: |
         du -sh $(Build.SourcesDirectory)/*
         df -h
index 3f01453..f3de87e 100644 (file)
@@ -70,19 +70,13 @@ jobs:
         - ${{ parameters.variables }}
 
       steps:
-        - ${{ if eq(parameters.osGroup, 'OSX') }}:
-          - script: |
-              brew install pkgconfig icu4c openssl
-              brew link --force icu4c
-              ln -s /usr/local/opt/openssl/lib/pkgconfig/libcrypto.pc /usr/local/lib/pkgconfig/
-              ln -s /usr/local/opt/openssl/lib/pkgconfig/libssl.pc /usr/local/lib/pkgconfig/
-              ln -s /usr/local/opt/openssl/lib/pkgconfig/openssl.pc /usr/local/lib/pkgconfig/
-            displayName: Install Build Dependencies
-
         - ${{ if eq(parameters.isOfficialBuild, true) }}:
           - template: /eng/pipelines/common/restore-internal-tools.yml
 
-        - ${{ if in(parameters.osGroup, 'OSX', 'iOS','tvOS') }}: 
+        - ${{ if in(parameters.osGroup, 'OSX', 'iOS', 'tvOS') }}:
+          - script: sh $(Build.SourcesDirectory)/eng/install-native-dependencies.sh ${{ parameters.osGroup }}
+            displayName: Install Build Dependencies
+
           - script: |
               du -sh $(Build.SourcesDirectory)/*
               df -h
index 60d933d..743c501 100644 (file)
@@ -23,7 +23,7 @@ else()
 endif()
 
 if(NOT OPENSSL_FOUND)
-    message(FATAL_ERROR "!!! Cannot find libssl and System.Security.Cryptography.Native cannot build without it. Try installing libssl-dev (or the appropriate package for your platform) !!!. See the requirements document for your specific operating system: https://github.com/dotnet/runtime/tree/master/docs/workflow/requirements.")
+    message(FATAL_ERROR "!!! Cannot find libssl and System.Security.Cryptography.Native cannot build without it. Try installing libssl-dev (on Linux, but this may vary by distro) or openssl (on macOS) !!!. See the requirements document for your specific operating system: https://github.com/dotnet/runtime/tree/master/docs/workflow/requirements.")
 endif(NOT OPENSSL_FOUND)
 
 include_directories(${OPENSSL_INCLUDE_DIR})