diff --git a/.github/workflows/macos_build.yaml b/.github/workflows/macos_build.yaml new file mode 100644 index 0000000..e7f5ee5 --- /dev/null +++ b/.github/workflows/macos_build.yaml @@ -0,0 +1,62 @@ +name: MacOS Build + +on: + push: + branches: + - '**' + - '**' + pull_request: + branches: + - '**' + workflow_dispatch: + +jobs: + build: + runs-on: macos-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up environment + run: | + if ! command -v git &> /dev/null; then + echo "Git not found. Installing Git..." + brew install git + else + echo "Git is already installed." + fi + git --version + + brew install bash + echo "Bash version: $(bash --version)" + + brew install freetype + brew install harfbuzz + brew install odin + + make -C "/opt/homebrew/Cellar/odin/2024-10/libexec/vendor/stb/src" + + - name: Run build script + run: | + echo "Setting execute permissions on specific .sh files" + chmod +x ./scripts/build_sokol_demo.sh + chmod +x ./scripts/build_sokol_library.sh + chmod +x ./scripts/compile_sokol_shaders.sh + chmod +x ./scripts/clean.sh + chmod +x ./scripts/helpers/misc.sh + chmod +x ./scripts/helpers/odin_compiler_defs.sh + + echo "Running build_sokol_demo.sh" + ./scripts/build_sokol_demo.sh + shell: bash + + - name: List build artifacts + run: ls -R ./build || echo "build directory not found" + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: macos-build + path: ./build/ + if-no-files-found: warn diff --git a/scripts/build_sokol_demo.sh b/scripts/build_sokol_demo.sh index c63e82d..0cbfbdd 100644 --- a/scripts/build_sokol_demo.sh +++ b/scripts/build_sokol_demo.sh @@ -19,8 +19,22 @@ if [ -f "$path_system_details" ]; then CoreCount_Physical=$(grep "PhysicalCores" "$path_system_details" | cut -d'=' -f2) CoreCount_Logical=$(grep "LogicalCores" "$path_system_details" | cut -d'=' -f2) else - CoreCount_Physical=$(nproc --all) - CoreCount_Logical=$(nproc) + OS=$(uname -s) + case "$OS" in + Darwin*) + CoreCount_Physical=$(sysctl -n hw.physicalcpu) + CoreCount_Logical=$(sysctl -n hw.logicalcpu) + ;; + Linux*) + CoreCount_Physical=$(nproc --all) + CoreCount_Logical=$(nproc) + ;; + *) + echo "Unsupported operating system: $OS" + CoreCount_Physical=1 + CoreCount_Logical=1 + ;; + esac echo "[CPU]" > "$path_system_details" echo "PhysicalCores=$CoreCount_Physical" >> "$path_system_details" @@ -47,7 +61,19 @@ update_git_repo "$path_sokol" "$url_sokol" "$sokol_build_clibs_command" update_git_repo "$path_harfbuzz" "$url_harfbuzz" "./scripts/build.sh" pushd "$path_thirdparty" > /dev/null - path_harfbuzz_dlls="$path_harfbuzz/lib/linux64" + case "$OS" in + Darwin*) + path_harfbuzz_dlls="$path_harfbuzz/lib/osx" + ;; + Linux*) + path_harfbuzz_dlls="$path_harfbuzz/lib/linux64" + ;; + *) + echo "Unsupported operating system: $OS" + CoreCount_Physical=1 + CoreCount_Logical=1 + ;; + esac if ls "$path_harfbuzz_dlls"/*.so 1> /dev/null 2>&1; then cp "$path_harfbuzz_dlls"/*.so "$path_build/" else diff --git a/scripts/build_sokol_library.sh b/scripts/build_sokol_library.sh index e2cec23..71ce9a9 100644 --- a/scripts/build_sokol_library.sh +++ b/scripts/build_sokol_library.sh @@ -36,27 +36,45 @@ fi pushd "$path_sokol" -check_and_install() { - if ! dpkg -s $1 &> /dev/null; then - echo "$1 not found. Attempting to install..." - sudo apt update && sudo apt install -y $1 - if [ $? -ne 0 ]; then - echo "Failed to install $1. Please install manually and try again." - exit 1 - fi - fi -} +OS=$(uname -s) +case "$OS" in + Linux*) + echo "Detected Linux operating system" + # Check for OpenGL and X11 development libraries + check_and_install() { + if ! dpkg -s $1 &> /dev/null; then + echo "$1 not found. Attempting to install..." + sudo apt update && sudo apt install -y $1 + if [ $? -ne 0 ]; then + echo "Failed to install $1. Please install manually and try again." + exit 1 + fi + fi + } + # Uncomment these lines if you need to install these dependencies + # check_and_install libgl1-mesa-dev + # check_and_install libx11-dev + # check_and_install libxcursor-dev + # check_and_install libxrandr-dev + # check_and_install libxinerama-dev + # check_and_install libxi-dev + # check_and_install libasound2-dev # ALSA development library -# Check for OpenGL and X11 development libraries -# check_and_install libgl1-mesa-dev -# check_and_install libx11-dev -# check_and_install libxcursor-dev -# check_and_install libxrandr-dev -# check_and_install libxinerama-dev -# check_and_install libxi-dev -# check_and_install libasound2-dev # ALSA development library - -# Run the build script -./build_clibs_linux.sh + echo "Running Linux build script..." + ./build_clibs_linux.sh + ;; + Darwin*) + echo "Detected macOS operating system" + echo "Running macOS build script..." + ls -al + ./build_clibs_macos.sh + ;; + *) + echo "Unsupported operating system: $OS" + exit 1 + ;; +esac popd + +echo "Build process completed." diff --git a/scripts/compile_sokol_shaders.sh b/scripts/compile_sokol_shaders.sh index 695e215..6c36175 100644 --- a/scripts/compile_sokol_shaders.sh +++ b/scripts/compile_sokol_shaders.sh @@ -1,12 +1,28 @@ #!/bin/bash +OS=$(uname -s) + path_root="$(git rev-parse --show-toplevel)" path_backend="$path_root/backend" path_scripts="$path_root/scripts" path_thirdparty="$path_root/thirdparty" path_sokol_tools="$path_thirdparty/sokol-tools" -sokol_shdc="$path_sokol_tools/bin/linux/sokol-shdc" +case "$OS" in + Darwin*) + sokol_shdc="$path_sokol_tools/bin/osx/sokol-shdc" + ;; + Linux*) + sokol_shdc="$path_sokol_tools/bin/linux/sokol-shdc" + ;; + *) + echo "Unsupported operating system: $OS" + CoreCount_Physical=1 + CoreCount_Logical=1 + ;; +esac +echo "Using sokol-shdc: $sokol_shdc" +chmod +x "$sokol_shdc" path_backend_sokol="$path_backend/sokol" @@ -42,4 +58,6 @@ pushd "$path_backend_sokol" > /dev/null "$flag_target_lang" "glsl410:glsl300es:hlsl4:metal_macos:wgsl" \ "$flag_format_odin" "$flag_module=draw_text" +echo "Built sokol shaders" + popd > /dev/null diff --git a/scripts/helpers/misc.sh b/scripts/helpers/misc.sh index 3ad335c..2dc0a6c 100644 --- a/scripts/helpers/misc.sh +++ b/scripts/helpers/misc.sh @@ -67,6 +67,7 @@ update_git_repo() { echo "Building $url" pushd "$path" > /dev/null + chmod +x "$build_command" eval "$build_command" popd > /dev/null @@ -92,6 +93,7 @@ update_git_repo() { echo "Building $url" pushd "$path" > /dev/null + chmod +x "$build_command" eval "$build_command" popd > /dev/null