Skip to content

Using Packages

A Wyn dependency is a git repo, identified by its URL. There is no central registry, no account, and nothing to log into. You add a dependency, Wyn clones it into a shared cache, and import finds it. This is the Go/Deno model.

Add a Package

sh
wyn add args

A bare name expands to github.com/wynlang/<name> - this is the "official" marker. Packages under github.com/wynlang/* are maintained by the Wyn project; the GitHub org membership is the source of truth (there is no list to curate).

To add any repo, give its full path:

sh
wyn add github.com/bob/cool-lib          # any GitHub repo
wyn add github.com/bob/[email protected]     # pin a tag, branch, or commit
wyn add gitlab.com/team/utils            # any host, not just GitHub
  • Anything containing a / (or a URL) is taken as a full repo path. https:// is prepended if you omit the scheme.
  • @<ref> is an optional git ref: a tag, branch, or commit SHA. Without it, Wyn uses the repo's default-branch HEAD at add-time and pins the resolved commit in wyn.lock.

Override the import name

The last path segment becomes the import name by default. Use --as to change it (handy for URL adds or to avoid a collision between two repos named the same):

sh
wyn add github.com/bob/cool-lib --as cool
wyn
import cool

What wyn add writes

wyn add clones the repo into the cache and records two things in your project.

wyn.toml gets a line in [dependencies], mapping the short import name to url@ref:

toml
[project]
name = "myapp"
version = "0.1.0"
entry = "src/main.wyn"

[dependencies]
args = "github.com/wynlang/[email protected]"
cool = "github.com/bob/[email protected]"

wyn.lock pins the exact resolved commit for reproducible builds (one line per dep, whitespace-separated: name url ref commit-sha):

# wyn.lock - resolved dependency graph (do not edit by hand)
args https://github.com/wynlang/args v1.2 9f3a1c2e...
cool https://github.com/bob/cool-lib v0.3 44adf90b...

Commit both files. Teammates and CI run wyn restore to check out the exact same commits.

Import in Code

The short key in [dependencies] is the import name. Call a package's public functions through its namespace:

wyn
import args

fn main() {
    name = args.get("name")
    print("hello ${name}")
}

Package Commands

sh
wyn add <name|url>[@ref]      # Add a dependency; --as <name> overrides import name
wyn remove <name>            # Remove a dependency (cache untouched)
wyn list                     # List declared dependencies
wyn restore                  # Clone every dep from wyn.lock / wyn.toml, pinned

Each is also available under the wyn pkg prefix - wyn pkg add, wyn pkg install (alias for restore), wyn pkg remove, wyn pkg list - so existing muscle memory keeps working.

The Cache

Repos are cloned once into a global cache and shared across every project (like Go's module cache):

~/.wyn/pkg/<host>/<owner>/<repo>@<ref>/
  e.g. ~/.wyn/pkg/github.com/wynlang/[email protected]/
       ~/.wyn/pkg/github.com/bob/[email protected]/
  • A given url@ref is cloned exactly once; other projects reuse it.
  • Set WYN_PKG_CACHE to override the ~/.wyn/pkg location (used by CI and tests).

C Libraries

A handful of C libraries ship as curated built-in recipes. Adding one by its bare name runs the C bindgen and writes an [ffi] block into your wyn.toml - it does not go to GitHub:

sh
wyn add sqlite3

There are nine curated names - m (libm math), z (zlib), curl (libcurl), sqlite3 (SQLite), crypto and ssl (OpenSSL), curses (ncurses), readline, and xml2 (libxml2). The list is the source of truth, so check it any time with:

sh
wyn add --list

So the rule is: a bare name that matches a curated C recipe becomes a C library binding; anything with a /, a URL, or a bare name that is not a C recipe becomes a git dependency. To bind any other C library, see C FFI and Creating Packages.

Private Packages & Authentication

Because Wyn shells out to git clone, private repos work automatically through your ambient git authentication - whatever already lets you git clone the repo on the command line works here too. See Creating Packages for HTTPS-token, SSH, and CI setup.

See Also

MIT License - v1.21.0