Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
40c3513
Support package-named single-file modules
programmersd21 Oct 10, 2026
e6f6207
Support package-named single-file modules
programmersd21 Oct 10, 2026
e4172d9
Test imports from package-named single-file modules
programmersd21 Oct 10, 2026
42a1414
Prepare 0.14.0 version metadata and release notes
programmersd21 Oct 10, 2026
58fd2f4
Prepare 0.14.0 version metadata and release notes
programmersd21 Oct 10, 2026
e2b2a31
Prepare 0.14.0 version metadata and release notes
programmersd21 Oct 10, 2026
4237f4c
Prepare 0.14.0 version metadata and release notes
programmersd21 Oct 10, 2026
23cfeac
Prepare 0.14.0 version metadata and release notes
programmersd21 Oct 10, 2026
fb195fd
Prepare 0.14.0 version metadata and release notes
programmersd21 Oct 10, 2026
05a59e7
Prepare 0.14.0 version metadata and release notes
programmersd21 Oct 10, 2026
49cee91
Prepare 0.14.0 version metadata and release notes
programmersd21 Oct 10, 2026
7212632
Keep release versioning separate from package resolver fix
programmersd21 Oct 10, 2026
99c9b57
Keep release versioning separate from package resolver fix
programmersd21 Oct 10, 2026
28b5557
Keep release versioning separate from package resolver fix
programmersd21 Oct 10, 2026
ddf75ce
Keep release versioning separate from package resolver fix
programmersd21 Oct 10, 2026
88249ec
Keep release versioning separate from package resolver fix
programmersd21 Oct 10, 2026
8903941
Keep release versioning separate from package resolver fix
programmersd21 Oct 10, 2026
7832d36
Keep release versioning separate from package resolver fix
programmersd21 Oct 10, 2026
adf0791
Keep release versioning separate from package resolver fix
programmersd21 Oct 10, 2026
8b56b68
Document package-named module import resolution
programmersd21 Oct 10, 2026
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
26 changes: 18 additions & 8 deletions docs/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,39 @@ installs; the next install records the hashes. `pkg list` output is
unchanged.

Each dependency lands in `flint_modules/<name>/` with its sources and
its own `flint.toml`:
its own `flint.toml`. A package can expose its default module as
`main.fl`, as a same-named file such as `levenshtein/levenshtein.fl`,
or as a flat `flint_modules/<name>.fl` file.

```text
flint_modules/
libfoo/
flint.toml
foo.fl
main.fl
levenshtein/
flint.toml
levenshtein.fl
```

## imports and resolution

```flint
import "libfoo/foo.fl"
print(foo.hello())
import libfoo
print(libfoo.hello())

import levenshtein
print(levenshtein.distance("kitten", "sitting"))

import "gitlib/g.fl"
print(g.greet())
```

A quoted path with a `/` or a `.fl` extension is a file: relative to the
importing file, except `flint_modules/` is also searched, and packages
resolve before the standard library. A bare name (`import math`) is the
standard library.
A bare name first checks installed packages in `flint_modules/`:
`<name>/main.fl`, then `<name>/<name>.fl`, then the flat
`<name>.fl` layout. If no package matches, the standard library is
checked (so `import math` still imports the library). A quoted path with
a `/` or a `.fl` extension can address a file relative to the importing
file; package-internal paths are also resolved from `flint_modules/`.

## transitive dependencies

Expand Down
15 changes: 15 additions & 0 deletions rust/flintlang/c-src/src/runtime/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,21 @@ char *sys_resolve_module(const char *path)
main_file);
free(main_file);
}
/*
* Also support a single-file package named after
* itself, e.g. levenshtein/levenshtein.fl.
*/
if (found == NULL) {
size_t need_named = strlen(dir_main) + 1 +
pathlen + 3 + 1;
char *named = malloc(need_named);
if (named != NULL) {
snprintf(named, need_named, "%s/%s.fl",
dir_main, path);
found = pkg_candidate(named);
free(named);
}
}
if (found == NULL) {
size_t need2 =
strlen(dir_main) + 4;
Expand Down
15 changes: 15 additions & 0 deletions src/runtime/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,21 @@ char *sys_resolve_module(const char *path)
main_file);
free(main_file);
}
/*
* Also support a single-file package named after
* itself, e.g. levenshtein/levenshtein.fl.
*/
if (found == NULL) {
size_t need_named = strlen(dir_main) + 1 +
pathlen + 3 + 1;
char *named = malloc(need_named);
if (named != NULL) {
snprintf(named, need_named, "%s/%s.fl",
dir_main, path);
found = pkg_candidate(named);
free(named);
}
}
if (found == NULL) {
size_t need2 =
strlen(dir_main) + 4;
Expand Down
4 changes: 2 additions & 2 deletions tests/pkg_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ cat > "$WORK/gitsrc/flint.toml" <<'EOF'
name = "shout"
version = "0.3.0"
EOF
cat > "$WORK/gitsrc/main.fl" <<'EOF'
cat > "$WORK/gitsrc/shout.fl" <<'EOF'
export fn loud(who) {
return "HEY " + who
}
Expand Down Expand Up @@ -158,7 +158,7 @@ expect "git import works" "HEY zed" "$("$FLINT" use.fl 2>&1)"
pin=$(sed -n '/^commit = /s/commit = "\(.*\)"/\1/p' flint.lock)
expect "lock pins a 40-char commit" "40" "${#pin}"

cat > "$WORK/gitsrc/main.fl" <<'EOF'
cat > "$WORK/gitsrc/shout.fl" <<'EOF'
export fn loud(who) {
return "LOUDER " + who
}
Expand Down
Loading