gomod

package
v1.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gomod scaffolds the throwaway Go module that `lg` generates around emitted Go sources before handing them to `go build`.

It was extracted from the WASM build path, which was its only caller and had the module name baked in. The AOT native path (nooga/let-go#596) needs the same three behaviors — pin a released binary's require to its own version, prefer a local source tree in dev builds, fall back to the module proxy — so this exists to keep one implementation rather than two. A fourth behavior serves a custom host built on pkg/cli: reproduce the host's own `replace` directive for let-go verbatim (GenerateWithReplace), so its -w builds against the let-go it actually links.

Index

Constants

View Source
const ModulePath = "github.com/nooga/let-go"

ModulePath is the let-go module the generated module requires.

Variables

This section is empty.

Functions

func FindLetGoSourceDir

func FindLetGoSourceDir() (string, error)

FindLetGoSourceDir locates a let-go checkout to build against: LETGO_SRC if set, else the module root above the current directory, else the one above the running executable.

func GoToolPath

func GoToolPath() string

GoToolPath returns the `go` binary to invoke, preferring the one under the GOROOT this binary was built with so a build doesn't silently pick a different toolchain off PATH.

func ReleaseRef

func ReleaseRef(version string) (string, bool)

ReleaseRef reports the module ref a released binary should pin to, and whether this version is a release at all. A version is a release when it starts with a digit: "dev" and "" are not, so they fall through to the local-source and proxy paths.

Types

type Files

type Files struct {
	Mod string
	Sum []byte
}

Files is a generated module's go.mod text and go.sum bytes. Sum is empty when the local-source path supplied no go.sum.

func Generate

func Generate(dir, moduleName, version string) (Files, error)

func GenerateWithReplace

func GenerateWithReplace(dir, moduleName string, rep Replacement) (Files, error)

GenerateWithReplace produces go.mod/go.sum for a module named moduleName in dir, requiring let-go through rep reproduced verbatim. It exists for a custom host whose go.mod replaces let-go: the host's module root is not let-go's, so FindLetGoSourceDir cannot recover a directory replacement, and a module replacement is not a version of github.com/nooga/let-go at all. Collapsing either to a version silently built the WASM module against a different let-go (or @latest); reproducing the directive builds it against the one the host links.

A directory replacement must be absolute and must hold let-go's module. Both failures are errors rather than fall-throughs: a binary that recorded `../let-go` has genuinely lost the path (build info carries no module root), and guessing a root would only move the surprise. LETGO_SRC is the override for that case; callers honor it before consulting build info.

type Replacement

type Replacement struct {
	Path    string
	Version string
}

Generate produces go.mod/go.sum for a module named moduleName, to be written in dir.

version is the lg binary's own version string ("dev" for an unreleased build). A released binary pins the require to its exact version so the generated program builds against the runtime it was emitted by; a dev build prefers the local source tree, and falls back to the module proxy at @latest when there isn't one. Replacement is the right-hand side of a go.mod `replace` directive for let-go, as a dependent binary's build info records it. Version is "" for a directory replacement; a module replacement carries the module path and its version, fork or not.

func (Replacement) IsDir

func (r Replacement) IsDir() bool

IsDir reports whether the replacement names a directory rather than a module.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL