-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add go
tutorial
#1032
Merged
+107
−6
Merged
docs: add go
tutorial
#1032
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ on: | |
tags: | ||
- "v*.*.*" | ||
pull_request: | ||
|
||
paths: | ||
- "src/**" | ||
- "Cargo.*" | ||
workflow_dispatch: | ||
|
||
name: CI | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Packaging a Go package | ||
|
||
This tutorial will guide you through making a Go package with `rattler-build`. | ||
|
||
When building a recipe for Go, most Go dependencies are linked statically. That | ||
means, we should collect their licenses and add them in the package. The | ||
`go-licenses` tool can help you with this task - as shown in the example below. | ||
|
||
## The different Go compilers | ||
|
||
The `conda-forge` ecosystem provides two go compilers: `go-cgo` and `go-nocgo`. | ||
|
||
By default, if you do not need to link against C libraries, it's recommended to | ||
use the `go-nocgo` compiler. It generates fat binaries without libc | ||
dependencies. The compiler activation scripts will set your `CC`, `CXX` and | ||
related flags to invalid values. | ||
|
||
The `go-cgo` compiler can generate fat binaries that depend on conda-forge's | ||
libc. You should use this compiler if the underlying program needs to link | ||
against other C libraries, in which case make sure to add `${{ compiler('c') }}` | ||
(`cxx`, `fortran`, ...) for unix and the `m2w64` equivalent for windows. | ||
|
||
## Example Go recipe | ||
|
||
This example shows how to package the [Temporal | ||
CLI](https://github.com/temporalio/cli). | ||
|
||
```yaml title="recipe.yaml" | ||
context: | ||
version: "0.13.1" | ||
|
||
package: | ||
name: temporal | ||
version: ${{ version }} | ||
|
||
source: | ||
url: https://github.com/temporalio/cli/archive/refs/tags/v${{ version }}.tar.gz | ||
sha256: 9d8812c96d3404490659fec3915dcd23c4142b421ef4cb7e9622bd9a459e1f74 | ||
|
||
build: | ||
number: 0 | ||
|
||
requirements: | ||
build: | ||
- ${{ compiler('go-nocgo') }} | ||
- go-licenses | ||
|
||
tests: | ||
- script: | ||
- temporal --version | ||
|
||
about: | ||
homepage: https://temporal.io | ||
repository: https://github.com/temporalio/cli | ||
documentation: https://docs.temporal.io/cli | ||
summary: Temporal CLI | ||
description: | | ||
Command-line interface for running Temporal Server and interacting with | ||
Workflows, Activities, Namespaces, and other parts of Temporal. | ||
license: MIT | ||
license_file: | ||
- LICENSE | ||
# These license files are generated at build time in the `build.sh` script | ||
# from all the dependencies of `temporal.io`. | ||
- license-files/ | ||
``` | ||
|
||
The build script (on Unix) should look something like this: | ||
|
||
```sh title="build.sh" | ||
# The LDFLAGS are used to set the version of the `temporal` binary. This is a common practice in Go. | ||
export LDFLAGS="${LDFLAGS} -s -w -X github.com/temporalio/cli/temporalcli.Version=${PKG_VERSION}" | ||
|
||
# Build the `temporal` binary and store it in the `$PREFIX/bin` directory. | ||
go build -ldflags "$LDFLAGS" -o $PREFIX/bin/temporal ./cmd/temporal | ||
|
||
# Store the license files in a separate directory in the $SRC_DIR. These are embedded in the package | ||
# in the `license_file` section. | ||
go-licenses save ./cmd/temporal --save_path="$SRC_DIR/license-files/" || true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please move the code blocks to concrete files so it is easier to test locally? Similar to how it is done here.
Mid-term it would be good to at run
rattler-build --render-only
on CI for a basic sanity check.