|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Copyright 2026 Google LLC |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +# Builds the shared library and places it in the shared directory. |
| 19 | +# This script handles OS detection to use the correct file extension. |
| 20 | + |
| 21 | +log() { |
| 22 | + echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" |
| 23 | +} |
| 24 | + |
| 25 | +log "Starting Spannerlib Shared Library Build for Node Wrapper..." |
| 26 | + |
| 27 | +# Resolve absolute paths |
| 28 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 29 | +SHARED_LIB_DIR="$(cd "$SCRIPT_DIR/../../../shared" && pwd)" |
| 30 | + |
| 31 | +log "Script Directory: $SCRIPT_DIR" |
| 32 | +log "Shared Lib Directory: $SHARED_LIB_DIR" |
| 33 | + |
| 34 | +# Auto-detect OS |
| 35 | +case "$(uname -s)" in |
| 36 | + Linux*) OS="Linux";; |
| 37 | + Darwin*) OS="macOS";; |
| 38 | + CYGWIN*|MINGW*|MSYS*) OS="Windows";; |
| 39 | + *) OS="Unknown";; |
| 40 | +esac |
| 41 | +log "Auto-detected OS: $OS" |
| 42 | + |
| 43 | +if [ "$OS" == "macOS" ]; then |
| 44 | + echo "Building for macOS..." |
| 45 | + go build -C "$SHARED_LIB_DIR" -o libspanner.dylib -buildmode=c-shared shared_lib.go |
| 46 | +elif [ "$OS" == "Linux" ]; then |
| 47 | + echo "Building for Linux..." |
| 48 | + go build -C "$SHARED_LIB_DIR" -o libspanner.so -buildmode=c-shared shared_lib.go |
| 49 | +elif [ "$OS" == "Windows" ]; then |
| 50 | + echo "Building for Windows..." |
| 51 | + go build -C "$SHARED_LIB_DIR" -o spannerlib.dll -buildmode=c-shared shared_lib.go |
| 52 | +else |
| 53 | + echo "Unsupported operating system: $OS" |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +echo "Build complete." |
0 commit comments