Merge pull request #7087 from abyss7/issue-6459

Add instruction for cross-compilation for Mac OS X
This commit is contained in:
alexey-milovidov 2019-09-24 19:58:55 +03:00 committed by GitHub
commit ebb92d656d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 8 deletions

View File

@ -118,6 +118,13 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, cache, di
cmake_flags.append('-DCMAKE_C_COMPILER=`which {}`'.format(cc)) cmake_flags.append('-DCMAKE_C_COMPILER=`which {}`'.format(cc))
cmake_flags.append('-DCMAKE_CXX_COMPILER=`which {}`'.format(cxx)) cmake_flags.append('-DCMAKE_CXX_COMPILER=`which {}`'.format(cxx))
if "darwin" in compiler:
cmake_flags.append("-DCMAKE_AR:FILEPATH=/cctools/bin/x86_64-apple-darwin-ar") \
.append("-DCMAKE_RANLIB:FILEPATH=/cctools/bin/x86_64-apple-darwin-ranlib") \
.append("-DCMAKE_SYSTEM_NAME=Darwin") \
.append("-DSDK_PATH=/cctools/MacOSX10.14.sdk") \
.append("-DLINKER_NAME=/cctools/bin/x86_64-apple-darwin-ld")
if sanitizer: if sanitizer:
result.append("SANITIZER={}".format(sanitizer)) result.append("SANITIZER={}".format(sanitizer))
if build_type: if build_type:
@ -166,12 +173,12 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, cache, di
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s') logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
parser = argparse.ArgumentParser(description="ClickHouse building script via virtualization mechanisms") parser = argparse.ArgumentParser(description="ClickHouse building script using prebuilt Docker image")
parser.add_argument("--package-type", choices=IMAGE_MAP.keys(), required=True) parser.add_argument("--package-type", choices=IMAGE_MAP.keys(), required=True)
parser.add_argument("--clickhouse-repo-path", default="../../") parser.add_argument("--clickhouse-repo-path", default="../../")
parser.add_argument("--output-dir", required=True) parser.add_argument("--output-dir", required=True)
parser.add_argument("--build-type", choices=("debug", ""), default="") parser.add_argument("--build-type", choices=("debug", ""), default="")
parser.add_argument("--compiler", choices=("clang-6.0", "clang-7", "gcc-7", "clang-8", "gcc-8", "gcc-9"), default="gcc-7") parser.add_argument("--compiler", choices=("clang-6.0", "clang-7", "gcc-7", "clang-8", "clang-8-darwin", "gcc-8", "gcc-9"), default="gcc-7")
parser.add_argument("--sanitizer", choices=("address", "thread", "memory", "undefined", ""), default="") parser.add_argument("--sanitizer", choices=("address", "thread", "memory", "undefined", ""), default="")
parser.add_argument("--unbundled", action="store_true") parser.add_argument("--unbundled", action="store_true")
parser.add_argument("--split-binary", action="store_true") parser.add_argument("--split-binary", action="store_true")

View File

@ -10,7 +10,7 @@ $ sudo apt-get install git pbuilder debhelper lsb-release fakeroot sudo debian-a
## Checkout ClickHouse Sources ## Checkout ClickHouse Sources
```bash ```bash
$ git clone --recursive --branch stable https://github.com/yandex/ClickHouse.git $ git clone --recursive --branch master https://github.com/ClickHouse/ClickHouse.git
$ cd ClickHouse $ cd ClickHouse
``` ```
@ -55,7 +55,7 @@ $ sudo apt-get install gcc-9 g++-9
### Install from Sources ### Install from Sources
Look at [utils/ci/build-gcc-from-sources.sh](https://github.com/yandex/ClickHouse/blob/master/utils/ci/build-gcc-from-sources.sh) Look at [utils/ci/build-gcc-from-sources.sh](https://github.com/ClickHouse/ClickHouse/blob/master/utils/ci/build-gcc-from-sources.sh)
## Use GCC 9 for Builds ## Use GCC 9 for Builds
@ -73,16 +73,14 @@ $ sudo apt-get install libicu-dev libreadline-dev gperf
## Checkout ClickHouse Sources ## Checkout ClickHouse Sources
```bash ```bash
$ git clone --recursive git@github.com:yandex/ClickHouse.git $ git clone --recursive git@github.com:ClickHouse/ClickHouse.git
``` ```
or or
```bash ```bash
$ git clone --recursive https://github.com/yandex/ClickHouse.git $ git clone --recursive https://github.com/ClickHouse/ClickHouse.git
$ cd ClickHouse $ cd ClickHouse
``` ```
For the latest stable version, switch to the `stable` branch.
## Build ClickHouse ## Build ClickHouse
```bash ```bash

View File

@ -0,0 +1,53 @@
# How to Build ClickHouse on Linux for Mac OS X
The cross-build for Mac OS X is based on the Build instructions, follow them first.
# Install Clang-8
Follow the instructions from https://apt.llvm.org/ for your Ubuntu or Debian setup.
For example the commands for Bionic are like:
```bash
sudo echo "deb [trusted=yes] http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main" >> /etc/apt/sources.list
sudo apt-get install clang-8
```
# Install Cross-Compilation Toolset
```bash
mkdir cctools
git clone https://github.com/tpoechtrager/apple-libtapi.git
cd apple-libtapi
INSTALLPREFIX=../cctools ./build.sh
./install.sh
cd ..
git clone https://github.com/tpoechtrager/cctools-port.git
cd cctools-port/cctools
./configure --prefix=../cctools --with-libtapi=../cctools --target=x86_64-apple-darwin
make install
cd ..
cd cctools
wget https://github.com/phracker/MacOSX-SDKs/releases/download/10.14-beta4/MacOSX10.14.sdk.tar.xz
tar xJf MacOSX10.14.sdk.tar.xz
```
Let's remember the path where we created `cctools` directory as ${CCTOOLS_PARENT}
# Build ClickHouse
```bash
cd ClickHouse
mkdir build-osx
CC=clang-8 CXX=clang++-8 cmake . -Bbuild-osx -DCMAKE_SYSTEM_NAME=Darwin \
-DCMAKE_AR:FILEPATH=${CCTOOLS_PARENT}/cctools/bin/x86_64-apple-darwin-ar \
-DCMAKE_RANLIB:FILEPATH=${CCTOOLS_PARENT}/cctools/bin/x86_64-apple-darwin-ranlib \
-DLINKER_NAME=${CCTOOLS_PARENT}/cctools/bin/x86_64-apple-darwin-ld \
-DSDK_PATH=${CCTOOLS_PARENT}/cctools/MacOSX10.14.sdk \
-DUSE_SNAPPY=OFF -DENABLE_SSL=OFF -DENABLE_PROTOBUF=OFF -DENABLE_PARQUET=OFF -DENABLE_READLINE=OFF -DENABLE_ICU=OFF -DENABLE_FASTOPS=OFF
ninja -C build-osx
```
The resulting binary will have Mach-O executable format and can't be run on Linux.