diff --git a/.github/workflows/build-bgcode.yml b/.github/workflows/build-bgcode.yml new file mode 100644 index 0000000..b3fd529 --- /dev/null +++ b/.github/workflows/build-bgcode.yml @@ -0,0 +1,61 @@ +name: Build bgcode Binaries + +on: + workflow_dispatch: + push: + paths: + - '.github/workflows/build-bgcode.yml' + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + include: + - os: ubuntu-latest + artifact_name: bgcode-linux + binary_path: build/src/LibBGCode/cmd/bgcode + final_name: bgcode + - os: windows-latest + artifact_name: bgcode-windows + binary_path: build/src/LibBGCode/cmd/Release/bgcode.exe + final_name: bgcode.exe + - os: macos-latest + artifact_name: bgcode-macos + binary_path: build/src/LibBGCode/cmd/bgcode + final_name: bgcode_mac + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout libbgcode + uses: actions/checkout@v4 + with: + repository: prusa3d/libbgcode + submodules: true + + - name: Setup CMake + uses: jwlawson/actions-setup-cmake@v2.0 + with: + cmake-version: '3.25.x' + + - name: Configure and Build + run: | + cmake --preset default -DLibBGCode_BUILD_DEPS=ON + cmake --build --preset default --config Release + shell: bash + + - name: Rename Binary (macOS/Linux) + if: runner.os != 'Windows' + run: mv ${{ matrix.binary_path }} ${{ matrix.final_name }} + + - name: Rename Binary (Windows) + if: runner.os == 'Windows' + run: move ${{ matrix.binary_path }} ${{ matrix.final_name }} + shell: cmd + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.artifact_name }} + path: ${{ matrix.final_name }} \ No newline at end of file diff --git a/infra/networking/bgcode.py b/infra/networking/bgcode.py index 463e1bd..abf762b 100644 --- a/infra/networking/bgcode.py +++ b/infra/networking/bgcode.py @@ -1,16 +1,37 @@ import os import subprocess import tempfile -import shutil +import platform from pathlib import Path +def get_bgcode_binary(): + """Returns the path to the correct bgcode binary for the current platform.""" + addon_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + os_name = platform.system() + + if os_name == "Windows": + bin_name = "bgcode.exe" + elif os_name == "Darwin": # macOS + bin_name = "bgcode_mac" + else: # Linux/Other + bin_name = "bgcode" + + bin_path = os.path.join(addon_dir, "infra", "bin", bin_name) + + # Fallback to just "bgcode" if platform-specific one isn't found + if not os.path.exists(bin_path): + fallback_path = os.path.join(addon_dir, "infra", "bin", "bgcode") + if os.path.exists(fallback_path): + return fallback_path + + return bin_path + def convert_to_bgcode(gcode: str, name_part: str, compress: bool = True) -> bytes: """ Converts a G-code string to binary BGCode using the internal bgcode tool. Returns the binary content of the converted file. """ - addon_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) - bgcode_bin = os.path.join(addon_dir, "infra", "bin", "bgcode") + bgcode_bin = get_bgcode_binary() if not os.path.exists(bgcode_bin): raise FileNotFoundError(f"bgcode binary not found at {bgcode_bin}")