Files
Vintner/cmd/vintner/main.go
T
Cheviiot 738234186d Run wrapped tools directly as vintner <tool> ..., no PATH needed
`vintner cl ...`, `vintner msbuild ...`, etc. now work without adding
<dest>/bin/<arch> to PATH or relying on the same-directory symlinks
`install` sets up there. wrapper.Run gained an explicit binDir
parameter (empty string preserves the existing os.Executable()-based
self-location for the ordinary multi-call/symlink case) so
cmd/vintner's new runTool can point it at a resolved toolchain
directory instead.

Resolution order: VINTNER_BIN if set (same meaning as `env --bin` -
point it at a <dest>/bin/<arch> directory directly, for a non-default
--dest or a specific architecture), else <defaultToolchainDir>/bin/
<hostArch> - the layout a plain `vintner download && vintner install`
with no --dest override produces. A missing toolchain gets a clear
error pointing at both fixes, rather than bubbling up whatever
wineenv.Load's env.json error looks like.

Also fixed shell completion falling out of sync with the actual tool
list: the bash/zsh scripts previously hand-copied tool/flag names
(and had already gone stale once - --with-dxsdk was missing from the
download flag completions since it was added). The tool name list is
now generated from wrapper.ToolNames() instead of hand-maintained,
and both scripts now complete tool names too, so `vintner <TAB>`
suggests `cl`, `link`, `msbuild`, etc. alongside the management
subcommands.

Verified end-to-end with a minimal PATH (/usr/bin:/bin only, no
toolchain dir on it at all): `vintner cl /nologo hello.c` compiled
successfully, and `vintner msbuild -t:Rebuild ...` rebuilt the same
real KMDF driver verified earlier this session - both via the default
~/.vintner/bin/<hostArch> resolution, no VINTNER_BIN override needed.
2026-07-25 16:23:46 +10:00

69 lines
1.6 KiB
Go

// Command vintner cross compiles with the real MSVC toolchain on Linux
// via Wine. It's a multi-call binary that behaves as `cl`, `link`, `lib`,
// `rc`, `midl`, `mt`, `dumpbin`, `msbuild`, etc. when invoked under one of
// those names (via symlinks set up by `vintner install`) or as
// `vintner <tool> ...` directly (see runTool), and otherwise exposes the
// `download`/`install`/`env`/`version` management subcommands.
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/Cheviiot/vintner/internal/i18n"
"github.com/Cheviiot/vintner/internal/wrapper"
)
// version is set at build time via -ldflags "-X main.version=X.Y.Z";
// left as "dev" for plain `go build`/`go run`.
var version = "dev"
func main() {
base := filepath.Base(os.Args[0])
name := strings.TrimSuffix(strings.ToLower(base), ".exe")
if wrapper.IsTool(name) {
os.Exit(wrapper.Run(name, os.Args[1:], ""))
}
os.Exit(runCLI(os.Args[1:]))
}
func runCLI(args []string) int {
if len(args) == 0 {
printUsage()
return 1
}
if wrapper.IsTool(args[0]) {
return runTool(args[0], args[1:])
}
switch args[0] {
case "download", "dl":
return runDownload(args[1:])
case "install", "i":
return runInstall(args[1:])
case "env", "e":
return runEnv(args[1:])
case "completion":
return runCompletion(args[1:])
case "version", "v", "--version":
fmt.Println(versionString())
return 0
case "-h", "--help", "help", "h":
printUsage()
return 0
default:
fmt.Fprint(os.Stderr, i18n.T("main.unknown_subcommand", args[0]))
printUsage()
return 1
}
}
func printUsage() {
fmt.Fprint(os.Stderr, i18n.T("main.usage"))
}