Skip to content

Compile anything which implements Source#1684

Merged
simoncozens merged 2 commits intomainfrom
use-source-trait
Oct 7, 2025
Merged

Compile anything which implements Source#1684
simoncozens merged 2 commits intomainfrom
use-source-trait

Conversation

@simoncozens
Copy link
Copy Markdown
Contributor

Current, the input to the compiler API is Input - which admittedly makes sense, given the name. But it means that inputs are restricted to the set of source types enumerated in the Input enum. If we have people implementing their own source types (which we do!) then it makes sense for allow compilation of any object which impl Source. This pushes the creation of a Source from an Input higher up the pipeline, so that any Box<dyn Source> can be compiled.

Also improves the lifetime story of Workload to avoid messing with 'static - Workloads only need hang around as long as the Sources that they are compiling.

Copy link
Copy Markdown
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

This looks good to me, modulo me not being sure the lifetimes are necessary :)

Comment thread fontc/src/workload.rs Outdated
}

impl Workload {
impl<'a> Workload<'a> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

where does this lifetime parameter come from? More generally I don't think any of the lifetime additions in this patch are necessary? (if I just delete them all it still compiles)

@simoncozens
Copy link
Copy Markdown
Contributor Author

(I removed the lifetime business.)

@simoncozens simoncozens added this pull request to the merge queue Oct 7, 2025
Merged via the queue into main with commit ffa8189 Oct 7, 2025
12 checks passed
@simoncozens simoncozens deleted the use-source-trait branch October 7, 2025 17:47
anthrotype added a commit that referenced this pull request Dec 4, 2025
…rce> support

Refactor the compile arguments API to:
- Rename `fontc::Args` to `fontc::Options` for clarity (avoids confusion
  with CLI `args::Args`)
- Remove `input` field from Options - source is now passed separately
- Update `generate_font()` to accept `Box<dyn Source>` + `Options`
- Update `run()` to accept `Input` + `Options`

This restores the ability to pass custom `Box<dyn Source>` implementations
that was added in #1684, which library users need for generating their own
IR programmatically.

Also:
- Add `Default` derive to `Options` for ergonomic in-memory/WASM usage
- Rename `cli_args.rs` back to `args.rs` and delete `compile_args.rs` (Options inlined in lib.rs since it's short enough)
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.

2 participants