@@ -28,6 +28,7 @@ import (
2828 "github.com/googleapis/librarian/internal/librarian/rust"
2929 "github.com/googleapis/librarian/internal/yaml"
3030 "github.com/urfave/cli/v3"
31+ "golang.org/x/sync/errgroup"
3132)
3233
3334const (
@@ -191,28 +192,11 @@ func generate(ctx context.Context, language string, library *config.Library, cfg
191192 return nil , err
192193 }
193194 case languageRust :
194- sources := & rust.Sources {
195- Googleapis : googleapisDir ,
196- }
197- sources .Discovery , err = fetchSource (ctx , cfgSources .Discovery , discoveryRepo )
198- if err != nil {
199- return nil , err
200- }
201- sources .Conformance , err = fetchSource (ctx , cfgSources .Conformance , protobufRepo )
202- if err != nil {
203- return nil , err
204- }
205- sources .Showcase , err = fetchSource (ctx , cfgSources .Showcase , showcaseRepo )
195+ sources , err := fetchRustSources (ctx , cfgSources )
206196 if err != nil {
207197 return nil , err
208198 }
209- if cfgSources .ProtobufSrc != nil {
210- dir , err := fetchSource (ctx , cfgSources .ProtobufSrc , protobufRepo )
211- if err != nil {
212- return nil , err
213- }
214- sources .ProtobufSrc = filepath .Join (dir , cfgSources .ProtobufSrc .Subpath )
215- }
199+ sources .Googleapis = googleapisDir
216200 keep , err := rust .Keep (library )
217201 if err != nil {
218202 return nil , fmt .Errorf ("library %s: %w" , library .Name , err )
@@ -230,6 +214,53 @@ func generate(ctx context.Context, language string, library *config.Library, cfg
230214 return library , nil
231215}
232216
217+ // fetchRustSources fetches all source repositories needed for Rust generation
218+ // in parallel. It returns a rust.Sources struct with all directories populated.
219+ func fetchRustSources (ctx context.Context , cfgSources * config.Sources ) (* rust.Sources , error ) {
220+ sources := & rust.Sources {}
221+
222+ g , ctx := errgroup .WithContext (ctx )
223+ g .Go (func () error {
224+ dir , err := fetchSource (ctx , cfgSources .Discovery , discoveryRepo )
225+ if err != nil {
226+ return err
227+ }
228+ sources .Discovery = dir
229+ return nil
230+ })
231+ g .Go (func () error {
232+ dir , err := fetchSource (ctx , cfgSources .Conformance , protobufRepo )
233+ if err != nil {
234+ return err
235+ }
236+ sources .Conformance = dir
237+ return nil
238+ })
239+ g .Go (func () error {
240+ dir , err := fetchSource (ctx , cfgSources .Showcase , showcaseRepo )
241+ if err != nil {
242+ return err
243+ }
244+ sources .Showcase = dir
245+ return nil
246+ })
247+
248+ if cfgSources .ProtobufSrc != nil {
249+ g .Go (func () error {
250+ dir , err := fetchSource (ctx , cfgSources .ProtobufSrc , protobufRepo )
251+ if err != nil {
252+ return err
253+ }
254+ sources .ProtobufSrc = filepath .Join (dir , cfgSources .ProtobufSrc .Subpath )
255+ return nil
256+ })
257+ }
258+ if err := g .Wait (); err != nil {
259+ return nil , err
260+ }
261+ return sources , nil
262+ }
263+
233264func formatLibrary (ctx context.Context , language string , library * config.Library ) error {
234265 switch language {
235266 case languageFake :
0 commit comments