Refactor for cases when `.rs` needs to influence `.toml`

Open
#746 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Refactor
Clarity
Needs clarification
Activity status
Stale
Tech stack
rust
Domain
build-system

Research direction

Search the codebase for crate.addDependency and inspect the Module definition, LRO generation, and places that pre-emptively add dependencies. Compare the proposed dependency contract with the possible use.addDependency() approach before choosing a design. Done means applying the chosen approach to LRO and all similar dependency-generation sites so .rs generation can determine the required .toml dependencies.

Written by the indexing model from the issue text.

Description

CodeGen

In #745, we moved writing .toml to disk after generating the .rs files. Which works, but it is not the clearest design possible.

We have discussed a few ideas offline, how can refactor it to be better:

Joel: "maybe instead of method(s) taking a crate parameter, we return any dependencies to be added in the Module definition. This formalizes the contract instead of passing crate which might get mutated and you need to know to emit Cargo.toml last"

Anton: "do you think it is a good idea to maybe expand Use to also take care of this? I.e. something like use.addDepencency()?"

Joel: "interesting idea. there is a relationship of sorts there."

If it looks good, we add use.AddDepencency(), use it in LRO, and also update all other places in the similar manner to add their dependencies as needed, i.e. search the code for crate.addDependency and move the logic from the places where we pre-emptively add a dependency ("if crate has clients") to places that need them (i.e. when we generate code for client, call use.addDependency()).

Dominant language
Rust
Stars
7
Forks
11
Avg merge
14h 15m
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/typespec-rust

All issues in Azure/typespec-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.