Skip to content
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
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/end-to-end.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
on:
push:
branches: [ main ]
paths:
- "src/**"
- "Cargo.*"
- "rust-tests/**"
- "test/end-to-end/**"
pull_request:
paths:
- "src/**"
- "Cargo.*"
- "rust-tests/**"
- "test/end-to-end/**"

name: End-to-End testing

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ on:
tags:
- "v*.*.*"
pull_request:

paths:
- "src/**"
- "Cargo.*"
workflow_dispatch:

name: CI
Expand Down
80 changes: 80 additions & 0 deletions docs/tutorials/go.md
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/
Comment on lines +29 to +65
Copy link
Contributor

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.

```

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
```
17 changes: 12 additions & 5 deletions docs/tutorials/javascript.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Packaging a Javascript (NPM/NodeJS) package

This tutorial will guide you though making a NodeJS package with `rattler-build`.
This tutorial will guide you though making a NodeJS package with
`rattler-build`. Please note that, while packaging executable applications is
possible, the conda ecosystem is not ideal for NPM libraries. NPM supports a
number of features that cannot easily be modeled in the conda ecosystem, such as
peer dependencies, optional dependencies, and the ability to install multiple
versions of the same package.

However, if you need to package a NodeJS application, `rattler-build` can help!

## Building a NodeJS Package

In this example, we will build a package for the NodeJS package `bibtex-tidy`.
We use `nodejs` in build and run requirements, and install the package using `npm`.
NPM comes as part of the NodeJS installation, so we do not need to install it separately.
We use `nodejs` in build and run requirements, and install the package using
`npm`. NPM comes as part of the NodeJS installation, so we do not need to
install it separately.

```yaml title="recipe.yaml"
context:
Expand Down Expand Up @@ -37,5 +45,4 @@ requirements:
tests:
- script:
- bibtex-tidy --version
```

```
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ nav:
- Examples:
- "Python": tutorials/python.md
- "C++": tutorials/cpp.md
- "Javascript": tutorials/javascript.md
- "Rust": tutorials/rust.md
- "Go": tutorials/go.md
- "Converting from conda-build": converting_from_conda_build.md

- Build options:
Expand Down