Skip to content

fix(v3): replace Unix-only shell commands in cross-compilation Taskfiles#5470

Merged
leaanthony merged 7 commits into
wailsapp:masterfrom
taliesin-ai:agent/engineer-linux/087e68b8
May 20, 2026
Merged

fix(v3): replace Unix-only shell commands in cross-compilation Taskfiles#5470
leaanthony merged 7 commits into
wailsapp:masterfrom
taliesin-ai:agent/engineer-linux/087e68b8

Conversation

@taliesin-ai

@taliesin-ai taliesin-ai commented May 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replaces bash-only shell constructs in cross-compilation Taskfiles with cross-platform Go tools, fixing Windows cross-compilation from the host.

New commands

  • wails3 tool has-cc — detects gcc/clang via exec.LookPath; replaces command -v gcc bash pattern
  • wails3 tool docker-mounts — generates Docker -v mount flags for the Go module cache and go.mod replace directives; replaces the bash pipeline that used grep, sed, and subshells

Why this supersedes PR #5332 and PR #5456

Both earlier PRs addressed code review feedback but could not be rebased due to permission constraints. This PR is a clean single-commit rebase on current master with all reviewer concerns addressed:

  1. Double quotes (not single) in -v flags — cmd.exe and PowerShell do not treat single quotes as string delimiters
  2. Windows drive-letter paths skippedC:\vendor\lib cannot be mapped to a valid Linux container path
  3. Unix absolute replace paths relativised — uses filepath.Rel(gomodDir, hostAbsPath) to map to /app/<rel> inside the container, matching where Go resolves the module

Tested on

  • Ubuntu 24.04.4 LTS, Go 1.25.0, gcc 13.3.0
  • wails3 tool has-cctrue (gcc present) / false (gcc absent) ✅
  • wails3 tool docker-mounts → correct GOPATH mount and replace-directive mounts ✅

Closes #5332
Closes #5456

Summary by CodeRabbit

Release Notes

  • New Features

    • Added docker-mounts CLI tool to generate Docker volume mount flags for cross-compilation builds.
    • Added has-cc CLI tool to detect C compiler availability in the system.
  • Refactor

    • Streamlined Docker cross-compilation setup for macOS, Linux, and Windows by consolidating mount generation logic.

Review Change Stack

Replace bash-only constructs with cross-platform Go tool implementations:
- wails3 tool has-cc: uses exec.LookPath for gcc/clang detection
- wails3 tool docker-mounts: generates -v flags with double quotes (cross-platform)
  and correct container path mapping for GOPATH and replace directives
  (relative paths map to /app/<rel>, Windows drive-letter paths are skipped,
  Unix absolute paths are relativised via filepath.Rel)
- Taskfiles updated to use Go tools instead of bash pipelines
- chown step guarded with platforms: [linux, darwin] to skip on Windows
@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR introduces two new wails3 tool subcommands (docker-mounts and has-cc) that replace Unix-only shell pipelines in cross-compilation Taskfiles, enabling cross-platform builds on Windows, macOS, and Linux without bash dependencies.

Changes

Cross-platform build tool integration

Layer / File(s) Summary
New CLI tool infrastructure
v3/internal/commands/tool_docker_mounts.go, v3/cmd/wails3/main.go
Implements ToolHasCC to detect C compiler availability via exec.LookPath, and ToolDockerMounts to parse go.mod for local replace directives and generate Docker -v mount flags for the Go module cache and dependency directories. Registers both tools as CLI subcommands (wails3 tool docker-mounts and wails3 tool has-cc).
Linux C compiler detection
v3/internal/commands/build_assets/linux/Taskfile.yml
Updates the HAS_CC variable to invoke wails3 tool has-cc instead of bash-only command -v gcc/clang check.
Taskfile Docker mount refactoring
v3/internal/commands/build_assets/darwin/Taskfile.yml, v3/internal/commands/build_assets/linux/Taskfile.yml, v3/internal/commands/build_assets/windows/Taskfile.yml
Replaces per-platform inline mount generation (GO_CACHE_MOUNT and REPLACE_MOUNTS shell pipelines) with a unified DOCKER_MOUNTS variable across darwin, linux, and windows build tasks, delegating mount computation to wails3 tool docker-mounts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

cli, v3-alpha

Suggested reviewers

  • leaanthony

Poem

A rabbit's build, now cross-platform true,
No bash required, just Go shining through!
Mounts and compilers, detected with care,
On Windows, macOS, Linux—everywhere! 🐰🐳

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing Unix-only shell commands in cross-compilation Taskfiles with cross-platform Go tools.
Description check ✅ Passed The PR description comprehensively documents the changes, motivations, and testing performed, meeting template requirements for bug fixes.
Linked Issues check ✅ Passed All coding objectives from linked issues are met: new wails3 tool has-cc and wails3 tool docker-mounts commands implemented, Taskfiles updated, double-quoted flags used, Windows paths skipped, Unix paths relativised.
Out of Scope Changes check ✅ Passed All changes directly support the stated objectives: CLI command registration, new Go tool implementations, and Taskfile updates to use these tools instead of bash constructs.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@v3/internal/commands/tool_docker_mounts.go`:
- Around line 95-103: The computed relative path "rel" from filepath.Rel (used
in the block that sets containerPath) can start with ".." and make
path.Clean("/app/"+rel) escape /app; update the logic in the function that
computes containerPath (references: gomodDir, hostAbsPath, rel, containerPath)
to detect and handle parent-directory components: after computing rel, reject or
sanitize any rel that begins with ".." or contains a ".." segment (e.g., with
strings.HasPrefix(rel, "..") or by scanning path segments), and only construct
containerPath when rel is safe; alternatively, build the candidate with
path.Clean("/app/"+filepath.ToSlash(rel)) and validate that the resulting
containerPath has the prefix "/app/" (or equals "/app") and skip or normalize
the mount when it does not to prevent escapes outside /app.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1e62010c-534d-4d65-82a1-55f7babf5750

📥 Commits

Reviewing files that changed from the base of the PR and between 42e853d and 5f5f959.

📒 Files selected for processing (5)
  • v3/cmd/wails3/main.go
  • v3/internal/commands/build_assets/darwin/Taskfile.yml
  • v3/internal/commands/build_assets/linux/Taskfile.yml
  • v3/internal/commands/build_assets/windows/Taskfile.yml
  • v3/internal/commands/tool_docker_mounts.go

Comment thread v3/internal/commands/tool_docker_mounts.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make v3 cross-compilation Taskfiles work from Windows hosts by replacing Unix-only shell constructs (command -v, grep|sed|tr pipelines, bash parameter expansion) with cross-platform wails3 tool subcommands.

Changes:

  • Added wails3 tool docker-mounts to generate Docker -v mount flags for the Go module cache and go.mod replace directives.
  • Added wails3 tool has-cc to detect presence of gcc/clang via exec.LookPath.
  • Updated darwin/linux/windows build Taskfiles to use DOCKER_MOUNTS and gate the chown $(id -u):$(id -g) step to non-Windows hosts; wired new subcommands into the CLI.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
v3/internal/commands/tool_docker_mounts.go Introduces docker-mounts + has-cc tool implementations used by Taskfiles.
v3/internal/commands/build_assets/windows/Taskfile.yml Replaces Unix shell-based mount generation with wails3 tool docker-mounts; gates chown to linux/darwin.
v3/internal/commands/build_assets/linux/Taskfile.yml Switches compiler detection to wails3 tool has-cc and mount generation to docker-mounts; gates chown.
v3/internal/commands/build_assets/darwin/Taskfile.yml Switches mount generation to docker-mounts; gates chown.
v3/cmd/wails3/main.go Registers the new tool docker-mounts and tool has-cc subcommands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread v3/internal/commands/tool_docker_mounts.go Outdated
Comment thread v3/internal/commands/tool_docker_mounts.go Outdated
Comment thread v3/internal/commands/tool_docker_mounts.go
The absolute-replace branch previously mapped paths under /app via
filepath.Rel(gomodDir, hostAbsPath), which only happens to match where
Go inside the container looks when the absolute path is a subpath of
the project root — and even then by coincidence. Go's modfile parser
keeps absolute replace paths verbatim and go build resolves them
literally, so the mount destination must equal the host absolute path
(matching the original Taskfile bash behaviour: -v $path:$path:ro).

Also removes the now-unused gomodDir local and updates comments.
Address Copilot review on PR wailsapp#5470:

- ToolDockerMounts now returns errors from os.ReadFile, modfile.Parse,
  and filepath.Abs instead of silently producing fewer mounts. A
  non-existent replace target is still skipped (matches original bash
  `if [ -d "$path" ]` behaviour, supports siblings not cloned on every
  machine).
- New tool_docker_mounts_test.go covers relative replaces (inside-
  project and ../sibling), Unix-absolute replace mounted at literal
  path, non-existent target silently skipped, missing go.mod returning
  an error, and a Windows-guarded drive-letter skip case. ToolHasCC has
  a smoke test asserting the output is exactly "true" or "false".
GOPATH on Windows always starts with a drive letter (C:\…), so the
GOPATH mount in the output will always contain "C:". Asserting that no
"C:" appears in the full output therefore made the test fail on Windows
even when the drive-letter replace directive was correctly skipped.
Check only that the replace-directive path (vendor/lib) is absent.
@leaanthony leaanthony merged commit 7ab1eb2 into wailsapp:master May 20, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants