gopack

package module
v0.0.0-...-3f99f61 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT, Unlicense Imports: 19 Imported by: 0

README

gopack

gopack is a (work in progress) tool that packages Gio programs into valid operating system packages.

For macOS this is a .app directory structure, and for Windows it's a .exe executable binary with an embedded icon resource.

The end goal for this tool is to be a single-command cross-platform build tool for Gio programs.

Contributions welcome!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTargets = []Target{
	NewTarget("windows/386"),
	NewTarget("windows/amd64"),
	NewTarget("windows/arm"),
	NewTarget("darwin/amd64"),

	NewTarget("linux/386"),
	NewTarget("linux/amd64"),
	NewTarget("linux/arm"),
	NewTarget("linux/arm64"),
	NewTarget("js/wasm"),
}

DefaultTargets is a static list of supported targets as a subset of output by `go tool dist list`.

Functions

This section is empty.

Types

type Architecture

type Architecture uint8

Architecture of the machine.

const (
	X86 Architecture = iota
	AMD64
	ARM
	ARM64
	WASM
)

Architectures supported.

func (*Architecture) FromStr

func (a *Architecture) FromStr(s string) Architecture

func (Architecture) List

func (a Architecture) List() []Architecture

func (Architecture) String

func (a Architecture) String() string

type Artifact

type Artifact struct {
	Binary io.Reader
	Target
}

Artifact associates a path to a binary with the platform it's intended for.

type FlagSet

type FlagSet struct {
	// Compiler flags.
	// go tool compile
	Compiler []string
	// Linker flags.
	// go tool link
	Linker []string
}

Flags contains tooling flags.

type Flags

type Flags map[Target]FlagSet

Flags maps tooling flags to Targets.

func (Flags) Lookup

func (f Flags) Lookup(target Target) FlagSet

Lookup the flags for a Target, returning an zero value if not FlagSet specified.

type MetaData

type MetaData struct {
	// Icon contains the image data for the icon.
	Icon   image.Image
	Darwin struct {
		// ICNS contains icon encoded as ICNS.
		ICNS io.Reader
		// Plist contains the Info.plist metadata file.
		Plist io.Reader
	}
	Windows struct {
		// ICO contains icon encoded as ICO.
		ICO io.Reader
		// Manifest contains the windows manifest metadata file.
		Manifest io.Reader
	}
	Linux struct {
	}
}

MetaData pulls together all platform specific metadata require to create a bundle.

Note: we don't care about the structure of the platform files, hence they are represented as blobs.

@Todo Generate plist, manifest, et al from common data (author, version, access requirements, etc). This would allow streamlined use, as the user wouldn't need to individually create such files; which is very much part of the mission statement of this software. If the user has already created those files for whatever reason, we can fallback to copying them.

func (*MetaData) Load

func (md *MetaData) Load(root string) error

Load metadata using defaults if not specified. For icons and other resources this means buffering the files in memory.

type Packer

type Packer struct {
	// Info contains information regarding the project to pack.
	Info *ProjectInfo
	// MetaData required to produce valid application bundles.
	MetaData MetaData
	// Artifacts that are generated by compilation.
	Artifacts []Artifact
	// PreCompile is run prior to compiling.
	// Allows modification of the compilation environment, such as generating a
	// Windows resource file to be compiled in.
	PreCompile func(root string, md MetaData, t Target) error
}

Packer packs a Go project into native artifacts and bundles.

func (*Packer) Compile

func (p *Packer) Compile() error

Compile the Go project. Requires Go toolchain to be installed. Compiles targets in parallel.

Note: copies source files to a sandbox for clean parallel compiles. This is IO heavy and was primary done because Windows requires a resource file to get linked to provide an icon for the binary. The presence of such file breaks compiles for other platforms.

@Enhance is there a more lightweight strategy that supports windows resource files? Such as manipulating the compiled PE directly.

func (Packer) Output

func (p Packer) Output() string

Output returns the output directory to place artifacts into.

func (Packer) Pack

func (p Packer) Pack() error

Pack the binaries into native formats.

type Platform

type Platform uint8

Platform identifier for the platforms we care about.

const (
	Windows Platform = iota
	Darwin
	Linux
	JS
)

Platforms supported.

func (*Platform) FromStr

func (p *Platform) FromStr(s string) Platform

func (Platform) List

func (p Platform) List() []Platform

func (Platform) String

func (p Platform) String() string

type ProjectInfo

type ProjectInfo struct {
	// Name specifies the output name of the artifact.
	// Defaults to the package name if empty.
	Name string
	// Root path to Go project.
	// Defaults to current working directory.
	Root string
	// Name of package to build.
	// Defaults to root if empty.
	Pkg string
	// Dist is the output directory to place Artifacts.
	// Defaults to "dist".
	Dist string
	// Flags are values to pass to the compiler.
	Flags Flags
	// Targets lists all targets to compile for.
	Targets []Target
}

ProjectInfo contains data required to compile a Go project.

type Target

type Target struct {
	Platform     Platform
	Architecture Architecture
}

func NewTarget

func NewTarget(s string) Target

func (Target) Ext

func (t Target) Ext() string

func (Target) String

func (t Target) String() string

Directories

Path Synopsis
cmd
pack
gopack is a tool for creating OS specific installable packages for Windows, macOS and Linux.
gopack is a tool for creating OS specific installable packages for Windows, macOS and Linux.
internal
ico
ico format encoding.
ico format encoding.

Jump to

Keyboard shortcuts

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