Skip to content

Commit d941250

Browse files
authored
Merge pull request #2547 from pavelzw/example-recipes-go
add go example recipe
2 parents 1da6623 + fad3e2f commit d941250

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

docs/_sidebar.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
"type": "doc",
5555
"id": "maintainer/example_recipes/index"
5656
},
57-
"items": ["maintainer/example_recipes/rust"]
57+
"items": [
58+
"maintainer/example_recipes/go",
59+
"maintainer/example_recipes/rust"
60+
]
5861
}
5962
]
6063
},

docs/maintainer/example_recipes/go.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: 'Go packages'
3+
---
4+
5+
If you want to package a Go package to conda-forge, you can use this recipe template:
6+
7+
```yaml
8+
context:
9+
name: example-package
10+
version: "0.1.0"
11+
12+
package:
13+
name: ${{ name|lower }}
14+
version: ${{ version }}
15+
16+
source:
17+
url: https://github.com/example-package/${{ name }}/archive/refs/tags/v${{ version }}.tar.gz
18+
sha256: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
19+
target_directory: src
20+
21+
build:
22+
number: 0
23+
script:
24+
- cd src
25+
- go-licenses save . --save_path ../library_licenses
26+
- if: unix
27+
then: go build -v -o $PREFIX/bin/example-package -ldflags="-s -w"
28+
else: go build -v -o %LIBRARY_BIN%\example-package.exe -ldflags="-s"
29+
30+
requirements:
31+
build:
32+
- ${{ compiler("go-nocgo") }}
33+
- go-licenses
34+
35+
tests:
36+
- script: example-package -help
37+
- package_contents:
38+
bin:
39+
- example-package
40+
strict: true
41+
42+
about:
43+
homepage: https://github.com/example-package/example-package
44+
summary: Summary of the package.
45+
description: |
46+
Description of the package
47+
license: MIT
48+
license_file:
49+
- src/LICENSE
50+
- library_licenses/
51+
documentation: https://pkg.go.dev/github.com/example-package/example-package
52+
repository: https://github.com/example-package/example-package
53+
54+
extra:
55+
recipe-maintainers:
56+
- LandoCalrissian
57+
```
58+
59+
This recipe template supports different features:
60+
61+
- Package licenses of statically linked libraries.
62+
- Ensure only binary is created by using `strict: true` in the `package_contents` tests.
63+
64+
If your package requires `cgo` instead of `go-nocgo`, you can use `${{ compiler("go-cgo") }}` instead to build the package. By default, the `go-nocgo` compiler [is used](https://github.com/conda-forge/staged-recipes/blob/main/.ci_support/linux64.yaml). Using `${{ compiler("go-cgo")) }}` also requires `${{ compiler("c") }}` and `${{ stdlib("c") }}` and may require `${{ compiler("cxx") }}` if C++ code is compiled. C/C++ build tools such as `make`, `autoconf`, `automake`, `libtool` or `cmake` may also be needed.
65+
66+
Sometimes, `go-licenses` might fail to detect licenses for some packages. In such cases, you can manually download the license file from the official source and add `--ignore github.com/bad-package/bad-package` to the `go-licenses` invokation. See [here](https://github.com/conda-forge/k9s-feedstock/blob/7929e0d86c829ba2ca172f08926f9fb7e6398247/recipe/recipe.yaml) for an example.
67+
68+
Some packages ship multiple binaries, in which case the `go build` command needs to be run separately for each binary.
69+
It is increasingly common for the go build command to require specifying a subdirectory, in which case the build steps would be slightly modified as shown below:
70+
71+
```bash
72+
go-licenses save ./cmd/example-package --save-path ../library_licenses
73+
go build -v -o ${PREFIX}/bin/example-package -ldflags="-s -w" ./cmd/example-package
74+
```
75+
76+
Some older Go packages that are not using Go modules yet can be converted by using:
77+
78+
```bash
79+
go mod init
80+
go mod tidy
81+
```
82+
83+
Additional steps maybe required depending on which Go dependency manager the project has been using.

0 commit comments

Comments
 (0)