Skip to content

Support explicit package library entry points - #14

Merged
programmersd21 merged 4 commits into
mainfrom
feat/package-lib-manifest
Oct 10, 2026
Merged

programmersd21 merged 4 commits into
mainfrom
feat/package-lib-manifest

Conversation

@programmersd21

@programmersd21 programmersd21 commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Add optional [package] lib = "src/api.fl" to select a package's public import entry point.
  • Resolve the declared path relative to the installed package root and reject unsafe paths or missing targets rather than silently falling back to a different module.
  • Preserve existing main.fl, same-named-file, and flat-file conventions when lib is absent.
  • Keep the standalone and Rust-embedded C runtime sources synchronized.
  • Document the manifest field and add an integration regression test.

Validation

  • CI is pending; keep this PR in draft until the checks pass.
  • This feature is intended for inclusion in 0.14.0; do not merge release PR Prepare 0.14.0 release metadata #12 before this feature and the other release fixes are integrated.

Summary by Sourcery

Support explicit, package-relative library entry points while preserving compatibility for packages without a lib declaration.

New Features:

  • Allow packages to declare an explicit public module entry point through the manifest lib field.

Bug Fixes:

  • Reject invalid or missing declared entry points instead of silently resolving a legacy module.

Enhancements:

  • Retain legacy package module layouts when no explicit entry point is configured.
  • Synchronize standalone and Rust-embedded runtime implementations.

Documentation:

  • Document the package lib manifest field and its resolution behavior.

Tests:

  • Add an integration regression test covering explicit library entry-point resolution and installation.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 97199fbf-5adf-4b19-8b3f-d7f4dcef0bf3

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Packages can now declare a safe, explicit .fl public entry point via [package] lib, which is resolved from the installed package root without falling back on errors; packages without the field retain legacy resolution, with synchronized C runtimes, documentation, and integration coverage.

Sequence diagram for explicit package library resolution

sequenceDiagram
    participant Importer
    participant Runtime
    participant Package
    participant EntryPoint

    Importer->>Runtime: sys_resolve_module(package)
    Runtime->>Package: pkg_declared_lib(package_dir, declared)
    Package-->>Runtime: declared lib path or no declaration
    alt valid declared lib
        Runtime->>EntryPoint: pkg_candidate(package_dir/lib)
        EntryPoint-->>Runtime: resolved module
    else declared lib invalid or missing
        Runtime-->>Importer: import error
    else no lib declaration
        Runtime->>Package: pkg_candidate(main.fl)
        Runtime->>Package: pkg_candidate(package/package.fl)
        Runtime->>Package: pkg_candidate(package.fl)
        Package-->>Runtime: legacy module match
    end
    Runtime-->>Importer: module path or failure
Loading

Flow diagram for package entry-point selection

flowchart TD
    A[Import package name] --> B[Locate installed package root]
    B --> C{"[package] lib declared?"}
    C -->|Yes| D[Validate relative .fl path inside package root]
    D --> E{Target exists?}
    E -->|Yes| F[Use declared public module]
    E -->|No| G[Reject import]
    D -->|Invalid| G
    C -->|No| H[Try main.fl]
    H --> I[Try same-named file]
    I --> J[Try flat package file]
Loading

File-Level Changes

Change Details Files
Add explicit package library entry-point selection with strict validation and legacy fallback behavior.
  • Parse optional [package] lib declarations from installed manifests.
  • Resolve only safe, existing .fl targets relative to the package root.
  • Treat declared-but-invalid or missing targets as non-fallback failures, while preserving legacy layouts when lib is absent.
src/runtime/sys.c
rust/flintlang/c-src/src/runtime/sys.c
Synchronize documentation with the new package manifest and import-resolution semantics.
  • Document lib syntax, relative-path constraints, error behavior, and compatibility layouts.
  • Clarify precedence between explicit entry points, legacy package layouts, and standard-library resolution.
docs/packages.md
Add an integration regression test for installed packages with explicit library entry points.
  • Create a dependency whose manifest points to src/api.fl while main.fl exposes a different result.
  • Verify installation copies the declared source and imports resolve to it.
tests/pkg_test.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@programmersd21
programmersd21 marked this pull request as ready for review October 10, 2026 15:10
@programmersd21
programmersd21 merged commit f7aea36 into main Oct 10, 2026
6 checks passed

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/runtime/sys.c" line_range="571-572" />
<code_context>
-							        need2,
-							        "%s.fl",
+					bool has_declared_lib = false;
+					found = pkg_declared_lib(
+					        dir_main, &has_declared_lib);
+					if (!has_declared_lib) {
+						size_t need = strlen(dir_main) + 9;
</code_context>
<issue_to_address>
**Invalid package entry point falls through**

When a declared `lib` target is missing or invalid and a same-named standard-library module or sibling `.fl` file is available, `sys_resolve_module` continues lookup, so the standard-library module or sibling file loads instead of the package import failing for its invalid entry point.

Stop resolution and report failure when a declared `lib` target cannot be resolved.

Also at `rust/flintlang/c-src/src/runtime/sys.c:571-573`, `src/runtime/sys.c:573`.
</issue_to_address>

### Comment 2
<location path="src/runtime/sys.c" line_range="497-499" />
<code_context>
+		if (*tail != '\0' && *tail != '#')
+			break;
+		*end = '\0';
+		size_t len = strlen(p);
+		if (len < 4 || strcmp(p + len - 3, ".fl") != 0 ||
+		        p[0] == '/' || strchr(p, '\\') != NULL)
+			break;
+		bool unsafe = false;
</code_context>
<issue_to_address>
**Hidden library files go missing**

When a package declares its library under a dot-prefixed file or directory, the resolver accepts the path, but package installation skips dot-prefixed entries, so the declared target is absent and importing the package fails.

Ensure declared library paths are copied during installation, or reject paths that installation will skip.

Also at `rust/flintlang/c-src/src/runtime/sys.c:497-499`, `src/runtime/sys.c:571-572`.
</issue_to_address>

### Comment 3
<location path="src/runtime/sys.c" line_range="571-572" />
<code_context>
-							        need2,
-							        "%s.fl",
+					bool has_declared_lib = false;
+					found = pkg_declared_lib(
+					        dir_main, &has_declared_lib);
+					if (!has_declared_lib) {
+						size_t need = strlen(dir_main) + 9;
</code_context>
<issue_to_address>
**Custom packages lack import hints**

When a user references a name from a package with a declared `lib` entry point but omits its import, `sys_module_file_exists` still checks only `flint_modules/<name>/main.fl`, so the undefined-name diagnostic does not recognize packages whose only entry point is declared with `lib`. Users who forget an import for such a package get no “forgot the import” hint.

Update `sys_module_file_exists` to use the same declared-entry-point lookup as the module resolver.

Also at `rust/flintlang/c-src/src/runtime/sys.c:571-572`.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: src/runtime/sys.c:572, src/runtime/sys.c:499


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/runtime/sys.c
Comment on lines +571 to +572
found = pkg_declared_lib(
dir_main, &has_declared_lib);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Invalid package entry point falls through

When a declared lib target is missing or invalid and a same-named standard-library module or sibling .fl file is available, sys_resolve_module continues lookup, so the standard-library module or sibling file loads instead of the package import failing for its invalid entry point.

Stop resolution and report failure when a declared lib target cannot be resolved.

Also at rust/flintlang/c-src/src/runtime/sys.c:571-573, src/runtime/sys.c:573.

Prompt for AI agents
In `src/runtime/sys.c` at lines 571-572:

**Invalid package entry point falls through**

When a declared `lib` target is missing or invalid and a same-named standard-library module or sibling `.fl` file is available, `sys_resolve_module` continues lookup, so the standard-library module or sibling file loads instead of the package import failing for its invalid entry point.

Stop resolution and report failure when a declared `lib` target cannot be resolved.

Also at `rust/flintlang/c-src/src/runtime/sys.c:571-573`, `src/runtime/sys.c:573`.

Comment thread src/runtime/sys.c
Comment on lines +497 to +499
size_t len = strlen(p);
if (len < 4 || strcmp(p + len - 3, ".fl") != 0 ||
p[0] == '/' || strchr(p, '\\') != NULL)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Hidden library files go missing

When a package declares its library under a dot-prefixed file or directory, the resolver accepts the path, but package installation skips dot-prefixed entries, so the declared target is absent and importing the package fails.

Ensure declared library paths are copied during installation, or reject paths that installation will skip.

Also at rust/flintlang/c-src/src/runtime/sys.c:497-499, src/runtime/sys.c:571-572.

Prompt for AI agents
In `src/runtime/sys.c` at lines 497-499:

**Hidden library files go missing**

When a package declares its library under a dot-prefixed file or directory, the resolver accepts the path, but package installation skips dot-prefixed entries, so the declared target is absent and importing the package fails.

Ensure declared library paths are copied during installation, or reject paths that installation will skip.

Also at `rust/flintlang/c-src/src/runtime/sys.c:497-499`, `src/runtime/sys.c:571-572`.

Comment thread src/runtime/sys.c
Comment on lines +571 to +572
found = pkg_declared_lib(
dir_main, &has_declared_lib);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ Low · Custom packages lack import hints

When a user references a name from a package with a declared lib entry point but omits its import, sys_module_file_exists still checks only flint_modules/<name>/main.fl, so the undefined-name diagnostic does not recognize packages whose only entry point is declared with lib. Users who forget an import for such a package get no “forgot the import” hint.

Update sys_module_file_exists to use the same declared-entry-point lookup as the module resolver.

Also at rust/flintlang/c-src/src/runtime/sys.c:571-572.

Prompt for AI agents
In `src/runtime/sys.c` at lines 571-572:

**Custom packages lack import hints**

When a user references a name from a package with a declared `lib` entry point but omits its import, `sys_module_file_exists` still checks only `flint_modules/<name>/main.fl`, so the undefined-name diagnostic does not recognize packages whose only entry point is declared with `lib`. Users who forget an import for such a package get no “forgot the import” hint.

Update `sys_module_file_exists` to use the same declared-entry-point lookup as the module resolver.

Also at `rust/flintlang/c-src/src/runtime/sys.c:571-572`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant