Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

xmake-go

/xmake-go

Buduje projekty Go w xmake: pliki binarne i biblioteki, moduły Go, kompilację krzyżową i współpracę z C przez cgo.

Repozytorium
xmake-skills ↗
Licencja
Apache-2.0
Ostatnia zmiana repozytorium
24.08.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 24.08.2026, bez odwołań do wycofanych modeli i API.

Licencja

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

Co robi i kiedy

Buduje projekty Go w xmake: pliki binarne i biblioteki, moduły Go, kompilację krzyżową i współpracę z C przez cgo.

Oryginalny opis (EN)

Use when building Go projects with xmake — binary/library targets with `.go` sources, go module integration, cross-compiling Go programs for other OS/arch, and mixing Go with C via cgo.

Jak działa

  1. 1. Minimal project
  2. 2. Target kinds
  3. 3. Go modules
  4. 4. Cross-compile
  5. 5. CGO (calling C from Go)
  6. 6. Toolchain selection
  7. 7. Flags
  8. 8. Tests
  9. Pitfalls
  10. When to branch out
Sekcje z nagłówków SKILL.md, w oryginale · 125 linii, 444 słów
Podgląd SKILL.md
---
name: xmake-go
description: Use when building Go projects with xmake — binary/library targets with `.go` sources, go module integration, cross-compiling Go programs for other OS/arch, and mixing Go with C via cgo.
---

# Building Go with Xmake

Xmake builds Go via the Go toolchain (`go build` under the hood, wrapped in xmake's target model). Useful if your project mixes Go with C/C++/Rust and you want a single build tool.

## 1. Minimal project

```bash
xmake create -l go -t console hello
cd hello
xmake run
```

```lua
add_rules("mode.debug", "mode.release")

target("hello")
    set_kind("binary")
    add_files("src/*.go")
```

## 2. Target kinds

```lua
target("app")       set_kind("binary")       -- executable
target("mylib")     set_kind("static")       -- Go archive
target("mydyn")     set_kind("shared")       -- Go shared lib (CGO-compatible)
```

## 3. Go modules

Keep a normal `go.mod` at the project root. Xmake picks it up automatically:

```
myproj/
├── xmake.lua
├── go.mod
├── go.sum
└── src/
    └── main.go
```

Dependencies declared in `go.mod` (`require github.com/... vX.Y.Z`) resolve through the Go toolchain as usual — xmake does not second-guess them.

## 4. Cross-compile

Go is famously easy to cross-compile, and xmake exposes it through standard flags:

```bash
xmake f -p windows -a x86_64
xmake                                    # builds a .exe from macOS/Linux

xmake f -p linux   -a arm64
xmake

xmake f -p macosx  -a arm64               # Apple Silicon
xmake
```

Xmake sets `GOOS` / `GOARCH` for you. Supported plats map to Go's naming automatically.

## 5. CGO (calling C from Go)

Keep `import "C"` in your `.go` files as usual. When building, add any C dependencies the Go code calls into:

```lua
target("app")
    set_kind("binary")
    add_files("src/*.go", "src/*.c")
    add_includedirs("include")
    add_links("foo")
```

Xmake compiles the `.c` files and links them alongside the Go objects.

## 6. Toolchain selection

```bash
xmake f --toolchain=go
xmake f --toolchain=go --sdk=/opt/go-1.22
```

`--sdk` pins a specific Go install; otherwise `go` on PATH is used.

## 7. Flags

```lua
target("app")
    add_files("src/*.go")
    add_gcflags("-N", "-l")               -- passed to `go tool compile`
    add_ldflags("-s -w")                  -- passed to `go tool link` (stripping)
```

`add_gcflags` is Go-specific (go **c**ompile flags). `add_ldflags` maps to `go tool link -ldflags`.

## 8. Tests

```lua
target("app_test")
    set_kind("binary")
    add_files("tests/*_test.go")
    add_tests("default")
```

Or run Go's native test runner as an xmake task:

```lua
task("gotest")
    set_menu { usage = "xmake gotest", description = "Run go test" }
    on_run(function () os.exec("go test ./...") end)
```

## Pitfalls

- **Editing `go.mod` after `xmake f`.** Run `xmake f -c` to re-resolve.
- **CGO disabled in cross-compile.** `CGO_ENABLED=0` is often required for pure-Go cross builds. Set it via env or `os.setenv` in `on_load`.
- **Mixing `.go` and `.cpp` (not `.c`) in one target.** Use `.c` for the C side; Go's CGO expects C, not C++.
- **`GOFLAGS` in env.** Sometimes overrides what xmake sets — `unset GOFLAGS` if you hit weird behavior.

## When to branch out

- CGO / mixing with C++ → `xmake-targets`
- Cross-compile flag plumbing → `xmake-cross-compilation`
- Packaging the built binary → `xmake-xpack`

Wersje

W bazie nie ma innych skilli o nazwie xmake-go.

Migawka bazy z 13.11.2026 · wersja paczki 621fb4546fd5 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100xmake-zig
    Buduje projekty Zig w xmake: pliki binarne i biblioteki, kompilację krzyżową oraz współpracę Zig z C.
  • 100xmake-nim
    Buduje projekty Nim w xmake: pliki binarne i biblioteki, wybór backendu C lub C++ i łączenie z kodem C.
  • 82cgo-bindings
    Wiąże Go z bibliotekami C lub Rust przez cgo: dyrektywy import C, konwersję łańcuchów znaków, zwalnianie pamięci i bezpieczeństwo wątków.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.