Skip to content

feat: add odin_library rule for collection-based package imports#7

Merged
clappingmonkey merged 1 commit into
mainfrom
feat/odin-library
Jul 8, 2026
Merged

feat: add odin_library rule for collection-based package imports#7
clappingmonkey merged 1 commit into
mainfrom
feat/odin-library

Conversation

@clappingmonkey

Copy link
Copy Markdown
Owner

What does this PR do?

Adds the rule — a source-aggregation rule that groups files and exposes them via so that targets can import them as Odin collections.

New files

  • odin/private/common.bzl — shared get_package_dir() helper (extracted from binary.bzl)
  • odin/private/library.bzlOdinLibraryInfo provider + odin_library rule
  • e2e/smoke/lib/greetings.odin — library test source

Modified files

  • odin/private/binary.bzl — added deps attr, -collection:<name>=<root> flags, dep srcs in action inputs, duplicate collection name validation
  • odin/defs.bzl — exports odin_library
  • e2e/smoke/BUILD.bazelodin_library target + deps on odin_binary
  • e2e/smoke/hello/hello.odin — imports library via import greetings "greetings:lib"
  • README.md — documents odin_library + deps attr

Design

  • odin_library is source aggregation only (no compilation step)
  • Collection name = the label name of the odin_library target
  • Collection root = parent directory of the package directory
  • odin_binary consumes deps by passing -collection:<name>=<root> to the Odin compiler
  • Odin uses the directory name as the default import alias (not the package declaration name), so users should use import myname "collection:dir" for explicit aliases

Edge cases handled

  • Empty deps → backward compatible (existing odin_binary works unchanged)
  • Duplicate collection names across deps → fail() with clear error
  • Root-level srcs (no parent dir) → fail() with clear error
  • Lockfile churn excluded from this PR

How was it tested?

  • bazel build //... in root workspace — passes
  • cd e2e/smoke && bazel build //... — passes
  • ./e2e/smoke/bazel-bin/hello — prints both "Hellope, Odin from Bazel!" and "Greetings from the library, Bazel!"
  • pre-commit run --all-files — buildifier + typos pass
  • Adversarial review by @change-validator — all 3 findings addressed (duplicate collection names, root-level srcs rejection, unused attrs removed)

Checklist

  • PR title follows conventional commit format
  • CI passes (check.yaml — lint + test matrix)
  • Tests: e2e smoke test updated with library dependency
  • Documentation: README updated with odin_library rule + deps attr
  • No breaking changes (existing odin_binary without deps works unchanged)

@clappingmonkey clappingmonkey merged commit e395c92 into main Jul 8, 2026
14 checks passed
@clappingmonkey clappingmonkey deleted the feat/odin-library branch July 8, 2026 08:13
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