fix(v3): replace Unix-only shell commands in cross-compilation Taskfiles#5470
Conversation
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
WalkthroughThis PR introduces two new ChangesCross-platform build tool integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
v3/cmd/wails3/main.gov3/internal/commands/build_assets/darwin/Taskfile.ymlv3/internal/commands/build_assets/linux/Taskfile.ymlv3/internal/commands/build_assets/windows/Taskfile.ymlv3/internal/commands/tool_docker_mounts.go
There was a problem hiding this comment.
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-mountsto generate Docker-vmount flags for the Go module cache andgo.modreplace directives. - Added
wails3 tool has-ccto detect presence ofgcc/clangviaexec.LookPath. - Updated darwin/linux/windows build Taskfiles to use
DOCKER_MOUNTSand gate thechown $(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.
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.
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 viaexec.LookPath; replacescommand -v gccbash patternwails3 tool docker-mounts— generates Docker-vmount flags for the Go module cache andgo.modreplace directives; replaces the bash pipeline that usedgrep,sed, and subshellsWhy 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:
-vflags —cmd.exeand PowerShell do not treat single quotes as string delimitersC:\vendor\libcannot be mapped to a valid Linux container pathfilepath.Rel(gomodDir, hostAbsPath)to map to/app/<rel>inside the container, matching where Go resolves the moduleTested on
wails3 tool has-cc→true(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
docker-mountsCLI tool to generate Docker volume mount flags for cross-compilation builds.has-ccCLI tool to detect C compiler availability in the system.Refactor