4coder/build_new/scripts/build-libs.sh

116 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
# =============================================================================
# Configuration
# =============================================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_DIR="$SCRIPT_DIR/../config"
# Source configuration files
source "$CONFIG_DIR/build-config.sh"
source "$HELPERS_DIR/print-routines.sh"
# =============================================================================
# Build Tree Sitter
# =============================================================================
build_tree_sitter_language() {
LANG_DIR=$1
LANG_NAME=$2
PARSER_SRC="${CUSTOM_ROOT}/lang/$LANG_DIR/parser.c"
PARSER_OUT="$TEMP_OUT_DIR/${LANG_DIR}_parser.o"
SCANNER_SRC="${CUSTOM_ROOT}/lang/$LANG_DIR/scanner.cc"
SCANNER_OUT="$TEMP_OUT_DIR/${LANG_DIR}_scanner.o"
if [ ! -f $SCANNER_SRC ]; then
SCANNER_SRC="${CUSTOM_ROOT}/lang/$LANG_DIR/scanner.c"
fi
print_step "Building tree-sitter $LANG_NAME Language Lib ($LANG_DIR)"
BUILT_ANYTHING=0
if [ -f $PARSER_SRC ]; then
echo " Building Parser..."
clang $CLANG_OPTS "${INCLUDES[@]}" "$PARSER_SRC" -o "$PARSER_OUT"
if [ $? == 0 ]; then
BUILT_ANYTHING=1
fi
fi
if [ -f $SCANNER_SRC ]; then
echo " Building Scanner..."
clang $CLANG_OPTS "${INCLUDES[@]}" "$SCANNER_SRC" -o "$SCANNER_OUT"
if [ $? == 0 ]; then
BUILT_ANYTHING=1
fi
fi
if [ $BUILT_ANYTHING == 1 ]; then
print_success "Complete"
else
print_warning "Failed to build anything."
fi
}
build_tree_sitter() {
BIN_NAME="custom_4coder"
CUSTOM_ROOT="$FOREIGN_DIR/tree-sitter"
INCLUDES=(
"-I$CUSTOM_ROOT/lib/src"
"-I$CUSTOM_ROOT/lib/include"
)
CLANG_OPTS=(
"-c" # Compile, don't link
"-O2" # Compile in release, regardless of 4coder build mode
"-g" # Debug info
)
TEMP_OUT_DIR=$BUILD_TEMP_DIR/tree-sitter
mkdir -p $TEMP_OUT_DIR
rm $TEMP_OUT_DIR/*.o
rm "$BUILD_TEMP_DIR/tree-sitter.a"
# Build tree-sitter.lib/.a
print_step "Building tree-sitter lib"
clang $CLANG_OPTS "${INCLUDES[@]}" "$CUSTOM_ROOT/lib/src/lib.c" -o $TEMP_OUT_DIR/tree-sitter.o
print_success "Complete"
build_tree_sitter_language "cpp" "C++"
build_tree_sitter_language "jai" "Jai"
build_tree_sitter_language "bash" "Bash"
build_tree_sitter_language "ts" "Typescript"
# Link tree-sitter lib and parser obj files into a static library to link into main custom dll
print_step "Linking tree-sitter static library"
ar rcs $BUILD_TEMP_DIR/tree-sitter.a $TEMP_OUT_DIR/*.o
print_success "Completed"
}
# =============================================================================
# Main
# =============================================================================
main() {
local config="${1:-debug}"
local arch="${2:-x64}"
print_step "macOS Build Process"
print_info "Configuration: $config"
print_info "Architecture: $arch"
# Create build directory
mkdir -p "$BUILD_DIR"
# Execute build steps
build_tree_sitter
}
# Only run main if script is executed directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi