Skip to content

Provide a deployment rule #36

@Vertexwahn

Description

@Vertexwahn

It would be nice if there were a rule that helps in deploying a Qt application

Current approach looks like this:

genrule(
    name = "okapi_ui_windows_portable",
    srcs = [
        ":okapi.ui",
        "okapi.ui.qss",
        "okapi.ui.ico",
        "license_notes.txt",
    ] + glob(["scenes/**/*"]),
    outs = ["okapi_ui_windows_portable.zip"],
    cmd = select({
        "@platforms//os:windows": """
            # Create temp directory for packaging
            TEMP_DIR=$$(mktemp -d)
            PACKAGE_DIR="$$TEMP_DIR"
            mkdir -p "$$PACKAGE_DIR"
            
            # Copy the executable to root
            EXE_PATH="$$(realpath "$(execpath :okapi.ui)")"
            EXE_NAME="$$(basename "$$EXE_PATH")"
            cp "$$EXE_PATH" "$$PACKAGE_DIR/$$EXE_NAME"
            
            # Copy icon to root
            cp "$(execpath okapi.ui.ico)" "$$PACKAGE_DIR/"
            
            # Copy qss and license_notes.txt to okapi/ui/
            mkdir -p "$$PACKAGE_DIR/okapi/ui"
            cp "$(execpath okapi.ui.qss)" "$$PACKAGE_DIR/okapi/ui/"
            cp "$(execpath license_notes.txt)" "$$PACKAGE_DIR/okapi/ui/"
            
            # Use windeployqt to deploy Qt dependencies
            # Find windeployqt.exe in the Qt Bazel external repository
            # The path needs to be resolved relative to the execution root
            WINDEPLOYQT=""
            
            # Check common Bazel external repository locations
            for base_dir in "external" ".."; do
                for repo_name in "rules_qt++fetch+qt_windows_x86_64" "qt_windows_x86_64"; do
                    windeployqt_path="$$base_dir/$$repo_name/bin/windeployqt.exe"
                    if [ -f "$$windeployqt_path" ]; then
                        # Convert to Windows path format
                        WINDEPLOYQT="$$(realpath -m "$$windeployqt_path" 2>/dev/null || echo "$$windeployqt_path")"
                        echo "Found windeployqt at: $$WINDEPLOYQT"
                        break 2
                    fi
                done
            done
            
            if [ -n "$$WINDEPLOYQT" ]; then
                cd "$$PACKAGE_DIR"
                echo "Running windeployqt on $$EXE_NAME..."
                "$$WINDEPLOYQT" --release --no-translations --no-system-d3d-compiler \
                    --no-compiler-runtime --no-opengl-sw "$$EXE_NAME" || {
                    echo "Warning: windeployqt failed with exit code $$?, continuing anyway..."
                }
                cd - > /dev/null
            else
                echo "ERROR: windeployqt.exe not found in Qt external repository"
                echo "Deployment will be incomplete - Qt DLLs/plugins not included"
            fi
            
            # Copy scenes folder to okapi/ui/scenes
            mkdir -p "$$PACKAGE_DIR/okapi/ui/scenes"
            for scene_file in $(SRCS); do
                if [[ "$$scene_file" == */scenes/* ]]; then
                    REL_PATH=$${scene_file#*scenes/}
                    TARGET_DIR="$$PACKAGE_DIR/okapi/ui/scenes/$$(dirname "$$REL_PATH")"
                    mkdir -p "$$TARGET_DIR"
                    cp "$$scene_file" "$$TARGET_DIR/"
                fi
            done
            
            # Create the ZIP archive
            OUTPUT_FILE="$$(realpath -m "$@" 2>/dev/null || echo "$@")"
            cd "$$TEMP_DIR"
            zip -r "$$OUTPUT_FILE" .
            
            # Cleanup
            cd -
            rm -rf "$$TEMP_DIR"
        """,
        "//conditions:default": "echo 'Windows only' > $@ && touch $@",
    }),
    tags = ["manual"],
    target_compatible_with = ["@platforms//os:windows"],
)

This can be transformed to a rules - e.g.
qt_windeployqt(
name = "deploy",
...
)

maybe for Ziping rules_pkg or some other rules can be used...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions