|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | +# |
| 20 | + |
| 21 | +set -e |
| 22 | + |
| 23 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" |
| 24 | +COMET_HOME_DIR=$SCRIPT_DIR/../.. |
| 25 | + |
| 26 | +function usage { |
| 27 | + local NAME=$(basename $0) |
| 28 | + cat <<EOF |
| 29 | +Usage: $NAME [options] |
| 30 | +
|
| 31 | +This script builds comet native binaries inside a docker image. The image is named |
| 32 | +"comet-rm" and will be generated by this script |
| 33 | +
|
| 34 | +Options are: |
| 35 | +
|
| 36 | + -r [repo] : git repo (default: ${REPO}) |
| 37 | + -b [branch] : git branch (default: ${BRANCH}) |
| 38 | + -t [tag] : tag for the spark-rm docker image to use for building (default: "latest"). |
| 39 | +EOF |
| 40 | +exit 1 |
| 41 | +} |
| 42 | + |
| 43 | +function cleanup() |
| 44 | +{ |
| 45 | + if [ $CLEANUP != 0 ] |
| 46 | + then |
| 47 | + echo Cleaning up ... |
| 48 | + if [ "$(docker ps -a | grep comet-arm64-builder-container)" != "" ] |
| 49 | + then |
| 50 | + docker rm comet-arm64-builder-container |
| 51 | + fi |
| 52 | + if [ "$(docker ps -a | grep comet-amd64-builder-container)" != "" ] |
| 53 | + then |
| 54 | + docker rm comet-amd64-builder-container |
| 55 | + fi |
| 56 | + CLEANUP=0 |
| 57 | + fi |
| 58 | +} |
| 59 | + |
| 60 | +trap cleanup SIGINT SIGTERM EXIT |
| 61 | + |
| 62 | +CLEANUP=1 |
| 63 | + |
| 64 | +REPO="https://github.com/apache/datafusion-comet.git" |
| 65 | +BRANCH="release" |
| 66 | +MACOS_SDK= |
| 67 | +HAS_MACOS_SDK="false" |
| 68 | +IMGTAG=latest |
| 69 | + |
| 70 | +while getopts "b:hr:t:" opt; do |
| 71 | + case $opt in |
| 72 | + r) REPO="$OPTARG";; |
| 73 | + b) BRANCH="$OPTARG";; |
| 74 | + t) IMGTAG="$OPTARG" ;; |
| 75 | + h) usage ;; |
| 76 | + \?) error "Invalid option. Run with -h for help." ;; |
| 77 | + esac |
| 78 | +done |
| 79 | + |
| 80 | +echo "Building binaries from $REPO/$BRANCH" |
| 81 | + |
| 82 | +WORKING_DIR="$SCRIPT_DIR/comet-rm/workdir" |
| 83 | +cp $SCRIPT_DIR/../cargo.config $WORKING_DIR |
| 84 | + |
| 85 | +# TODO: Search for Xcode (Once building macos binaries works) |
| 86 | +#PS3="Select Xcode:" |
| 87 | +#select xcode_path in `find . -name "${MACOS_SDK}"` |
| 88 | +#do |
| 89 | +# echo "found Xcode in $xcode_path" |
| 90 | +# cp $xcode_path $WORKING_DIR |
| 91 | +# break |
| 92 | +#done |
| 93 | + |
| 94 | +if [ -f "${WORKING_DIR}/${MACOS_SDK}" ] |
| 95 | +then |
| 96 | + HAS_MACOS_SDK="true" |
| 97 | +fi |
| 98 | + |
| 99 | +BUILDER_IMAGE_ARM64="comet-rm-arm64:$IMGTAG" |
| 100 | +BUILDER_IMAGE_AMD64="comet-rm-amd64:$IMGTAG" |
| 101 | + |
| 102 | +# Build the docker image in which we will do the build |
| 103 | +docker build \ |
| 104 | + --platform=linux/arm64 \ |
| 105 | + -t "$BUILDER_IMAGE_ARM64" \ |
| 106 | + --build-arg HAS_MACOS_SDK=${HAS_MACOS_SDK} \ |
| 107 | + --build-arg MACOS_SDK=${MACOS_SDK} \ |
| 108 | + "$SCRIPT_DIR/comet-rm" |
| 109 | + |
| 110 | +docker build \ |
| 111 | + --platform=linux/amd64 \ |
| 112 | + -t "$BUILDER_IMAGE_AMD64" \ |
| 113 | + --build-arg HAS_MACOS_SDK=${HAS_MACOS_SDK} \ |
| 114 | + --build-arg MACOS_SDK=${MACOS_SDK} \ |
| 115 | + "$SCRIPT_DIR/comet-rm" |
| 116 | + |
| 117 | +# Clean previous Java build |
| 118 | +pushd $COMET_HOME_DIR && ./mvnw clean && popd |
| 119 | + |
| 120 | +# Run the builder container for each architecture. The entrypoint script will build the binaries |
| 121 | + |
| 122 | +# AMD64 |
| 123 | +echo "Building amd64 binary" |
| 124 | +docker run \ |
| 125 | + --name comet-amd64-builder-container \ |
| 126 | + --memory 24g \ |
| 127 | + --cpus 6 \ |
| 128 | + -it \ |
| 129 | + --platform linux/amd64 \ |
| 130 | + $BUILDER_IMAGE_AMD64 "${REPO}" "${BRANCH}" amd64 |
| 131 | + |
| 132 | +if [ $? != 0 ] |
| 133 | +then |
| 134 | + echo "Building amd64 binary failed." |
| 135 | + exit 1 |
| 136 | +fi |
| 137 | + |
| 138 | +# ARM64 |
| 139 | +echo "Building arm64 binary" |
| 140 | +docker run \ |
| 141 | + --name comet-arm64-builder-container \ |
| 142 | + --memory 24g \ |
| 143 | + --cpus 6 \ |
| 144 | + -it \ |
| 145 | + --platform linux/arm64 \ |
| 146 | + $BUILDER_IMAGE_ARM64 "${REPO}" "${BRANCH}" arm64 |
| 147 | + |
| 148 | +if [ $? != 0 ] |
| 149 | +then |
| 150 | + echo "Building arm64 binary failed." |
| 151 | + exit 1 |
| 152 | +fi |
| 153 | + |
| 154 | +echo "Building binaries completed" |
| 155 | +echo "Copying to java build directories" |
| 156 | + |
| 157 | +JVM_TARGET_DIR=$COMET_HOME_DIR/common/target/classes/org/apache/comet |
| 158 | +mkdir -p $JVM_TARGET_DIR |
| 159 | + |
| 160 | +mkdir -p $JVM_TARGET_DIR/linux/amd64 |
| 161 | +docker cp \ |
| 162 | + comet-amd64-builder-container:"/opt/comet-rm/comet/native/target/release/libcomet.so" \ |
| 163 | + $JVM_TARGET_DIR/linux/amd64/ |
| 164 | + |
| 165 | +if [ "$HAS_MACOS_SDK" == "true" ] |
| 166 | +then |
| 167 | + mkdir -p $JVM_TARGET_DIR/darwin/x86_64 |
| 168 | + docker cp \ |
| 169 | + comet-amd64-builder-container:"/opt/comet-rm/comet/native/target/x86_64-apple-darwin/release/libcomet.dylib" \ |
| 170 | + $JVM_TARGET_DIR/darwin/x86_64/ |
| 171 | +fi |
| 172 | + |
| 173 | +mkdir -p $JVM_TARGET_DIR/linux/aarch64 |
| 174 | +docker cp \ |
| 175 | + comet-arm64-builder-container:"/opt/comet-rm/comet/native/target/release/libcomet.so" \ |
| 176 | + $JVM_TARGET_DIR/linux/aarch64/ |
| 177 | + |
| 178 | +if [ "$HAS_MACOS_SDK" == "true" ] |
| 179 | +then |
| 180 | + mkdir -p $JVM_TARGET_DIR/linux/aarch64 |
| 181 | + docker cp \ |
| 182 | + comet-arm64-builder-container:"/opt/comet-rm/comet/native/target/aarch64-apple-darwin/release/libcomet.dylib" \ |
| 183 | + $JVM_TARGET_DIR/darwin/aarch64/ |
| 184 | +fi |
| 185 | + |
| 186 | +# Build final jar |
| 187 | +echo "Building uber jar and publishing it locally" |
| 188 | +pushd $COMET_HOME_DIR |
| 189 | + |
| 190 | +GIT_HASH=$(git rev-parse --short HEAD) |
| 191 | +LOCAL_REPO=$(mktemp -d /tmp/comet-staging-repo-XXXXX) |
| 192 | + |
| 193 | +./mvnw "-Dmaven.repo.local=${LOCAL_REPO}" -P spark-3.4 -P scala-2.12 -DskipTests install |
| 194 | +./mvnw "-Dmaven.repo.local=${LOCAL_REPO}" -P spark-3.4 -P scala-2.13 -DskipTests install |
| 195 | +./mvnw "-Dmaven.repo.local=${LOCAL_REPO}" -P spark-3.3 -P scala-2.12 -DskipTests install |
| 196 | +./mvnw "-Dmaven.repo.local=${LOCAL_REPO}" -P spark-3.3 -P scala-2.13 -DskipTests install |
| 197 | +./mvnw "-Dmaven.repo.local=${LOCAL_REPO}" -P spark-3.5 -P scala-2.12 -DskipTests install |
| 198 | +./mvnw "-Dmaven.repo.local=${LOCAL_REPO}" -P spark-3.5 -P scala-2.13 -DskipTests install |
| 199 | + |
| 200 | +echo "Installed to local repo: ${LOCAL_REPO}" |
| 201 | + |
| 202 | +popd |
0 commit comments