Build Go, Rust and .NET projects
Go, Rust and .NET can all produce Windows programs from Linux with their own tools. This page shows what each one needs and what winbridge build runs for you.
The command is the same for every language
winbridge build path/to/projectLeave the path out to build the current folder. WinBridge looks at that folder only: it does not search subfolders or parent folders. In a repository with several packages, build one package folder at a time.
When more than one marker file is present, the first match in this order wins: Flutter, Go, Rust, .NET, C/C++.
Options that apply to every toolchain:
| Option | What it does |
|---|---|
--debug | Builds unoptimized, with debug information. |
-o, --output | Writes the result to a folder you choose. |
-- arguments | Passes everything after -- to the underlying compiler unchanged. |
--verbose | Prints every command and resolved tool path, as in winbridge --verbose build. |
The result lands in build/winbridge/windows-x64/ inside the project, named after the project.
Go
Go has cross-compiling built in, so it needs nothing but the Go toolchain.
Make sure Go is available.
If
gois already installed, WinBridge uses it. If not, let WinBridge install it into your home folder (67 MB):bashwinbridge doctor --install goBuild the module.
bashwinbridge build path/to/module
WinBridge detects a Go project by its go.mod file and names the output after the last part of the module path. It runs go build with GOOS=windows, GOARCH=amd64 and CGO_ENABLED=0. A release build adds -ldflags "-s -w", which strips debug symbols to make the file smaller; --debug leaves them in.
Good to know
cgo is switched off for these builds. A Go package that needs C code through cgo does not compile this way.
Extra arguments reach go build. For example, to add build tags:
winbridge build . -- -tags netgoRust
Rust needs three things: Cargo, the Windows target for the Rust standard library, and a MinGW linker that can write Windows executables.
Install Rust with
rustupif you have not already. WinBridge does not download Rust.Add the Windows target.
bashrustup target add x86_64-pc-windows-gnuInstall the MinGW-w64 linker. On Debian and Ubuntu:
bashsudo apt install gcc-mingw-w64-x86-64This provides
x86_64-w64-mingw32-gcc, the program WinBridge looks for.Build the crate.
bashwinbridge build path/to/crate
WinBridge detects a Rust project by Cargo.toml and runs cargo build --release --target x86_64-pc-windows-gnu. With --debug it leaves out --release. Cargo's target folder is kept in WinBridge's cache, so your project folder gains only the finished .exe.
If the Windows target is missing and rustup is installed, the build stops early and prints the rustup target add command to run.
Extra arguments reach cargo build:
winbridge build . -- --features cli.NET
The .NET SDK can publish for Windows from Linux. WinBridge does not download the SDK; install dotnet from Microsoft or your distribution.
winbridge build path/to/projectWinBridge detects a .NET project by a .csproj or .fsproj file in the folder and runs:
dotnet publish -r win-x64 -c Release --self-contained false -o <output folder>Things to know about the result:
- The build is framework-dependent: the Windows PC that runs it needs the matching .NET runtime installed.
- The output folder holds the launcher
.exetogether with the project's.dllfiles. Ship the whole folder, not only the.exe. - The project must produce a launcher
.exe. IfUseAppHostis disabled in the project file, the build fails with a message saying so. --debugdoes not change a .NET build. It always publishes theReleaseconfiguration.
Extra arguments reach dotnet publish:
winbridge build . -- -p:Version=1.2.3Check a project before building
winbridge detect shows what WinBridge would do, and builds nothing:
winbridge detect path/to/projectIt prints the project name, its type, the file that decided the type, and the toolchain that would build it.
Choose the Windows architecture
--target accepts windows-x64 (the default) and windows-arm64. In version 0.4.0 the check that follows every build accepts only 64-bit x86 executables, so use the default windows-x64.