Skip to content

Commit

Permalink
Simplify build on macOS (#35570)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored May 7, 2020
1 parent c2b1018 commit f6aad63
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 68 deletions.
7 changes: 2 additions & 5 deletions docs/workflow/building/coreclr/osx-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,18 @@ 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
```

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
Expand Down
39 changes: 3 additions & 36 deletions docs/workflow/requirements/macos-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
7 changes: 3 additions & 4 deletions eng/install-native-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions eng/pipelines/common/global-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion eng/pipelines/installer/jobs/base-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions eng/pipelines/libraries/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit f6aad63

Please sign in to comment.