Skip to content

Commit e9597f1

Browse files
authored
feat(internal/rust): run rustfmt and taplo fmt after generation (#3092)
1 parent 7ee8df4 commit e9597f1

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

internal/librarian/internal/rust/generate.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ package rust
1717
import (
1818
"context"
1919
"fmt"
20+
"path/filepath"
2021

22+
"github.com/googleapis/librarian/internal/command"
2123
"github.com/googleapis/librarian/internal/config"
2224
"github.com/googleapis/librarian/internal/fetch"
2325
"github.com/googleapis/librarian/internal/sidekick/parser"
@@ -47,7 +49,16 @@ func Generate(ctx context.Context, library *config.Library, sources *config.Sour
4749
if err != nil {
4850
return err
4951
}
50-
return sidekickrust.Generate(model, library.Output, sidekickConfig)
52+
if err := sidekickrust.Generate(model, library.Output, sidekickConfig); err != nil {
53+
return err
54+
}
55+
if err := command.Run("taplo", "fmt", filepath.Join(library.Output, "Cargo.toml")); err != nil {
56+
return err
57+
}
58+
if err := command.Run("cargo", "fmt", "-p", library.Name); err != nil {
59+
return err
60+
}
61+
return nil
5162
}
5263

5364
func sourceDir(ctx context.Context, source *config.Source, repo string) (string, error) {

internal/librarian/internal/rust/generate_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,24 @@ import (
2626

2727
func TestGenerate(t *testing.T) {
2828
cmdtest.RequireCommand(t, "protoc")
29+
cmdtest.RequireCommand(t, "rustfmt")
30+
cmdtest.RequireCommand(t, "taplo")
2931
testdataDir, err := filepath.Abs("../../../sidekick/testdata")
3032
if err != nil {
3133
t.Fatal(err)
3234
}
3335

34-
outDir := t.TempDir()
36+
// Change to testdata directory so cargo fmt can find Cargo.toml
37+
workspaceDir, err := filepath.Abs("testdata")
38+
if err != nil {
39+
t.Fatal(err)
40+
}
41+
outDir := filepath.Join(workspaceDir, "google-cloud-secretmanager-v1")
42+
t.Cleanup(func() { os.RemoveAll(outDir) })
43+
t.Chdir(workspaceDir)
3544
googleapisDir := filepath.Join(testdataDir, "googleapis")
3645
library := &config.Library{
37-
Name: "secretmanager",
46+
Name: "google-cloud-secretmanager-v1",
3847
Version: "0.1.0",
3948
Output: outDir,
4049
ReleaseLevel: "preview",
@@ -45,6 +54,15 @@ func TestGenerate(t *testing.T) {
4554
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
4655
},
4756
},
57+
Rust: &config.RustCrate{
58+
RustDefault: config.RustDefault{
59+
PackageDependencies: []*config.RustPackageDependency{
60+
{Name: "wkt", Package: "google-cloud-wkt", Source: "google.protobuf"},
61+
{Name: "iam_v1", Package: "google-cloud-iam-v1", Source: "google.iam.v1"},
62+
{Name: "location", Package: "google-cloud-location", Source: "google.cloud.location"},
63+
},
64+
},
65+
},
4866
}
4967
sources := &config.Sources{
5068
Googleapis: &config.Source{Dir: googleapisDir},
@@ -58,7 +76,7 @@ func TestGenerate(t *testing.T) {
5876
want string
5977
}{
6078
{filepath.Join(outDir, "Cargo.toml"), "name"},
61-
{filepath.Join(outDir, "Cargo.toml"), "secretmanager"},
79+
{filepath.Join(outDir, "Cargo.toml"), "google-cloud-secretmanager-v1"},
6280
{filepath.Join(outDir, "README.md"), "# Google Cloud Client Libraries for Rust - Secret Manager API"},
6381
{filepath.Join(outDir, "src", "lib.rs"), "pub mod model;"},
6482
{filepath.Join(outDir, "src", "lib.rs"), "pub mod client;"},
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[workspace]
2+
members = ["google-cloud-secretmanager-v1"]
3+
resolver = "2"
4+
5+
[workspace.package]
6+
edition = "2024"
7+
authors = ["Google LLC"]
8+
license = "Apache-2.0"
9+
repository = "https://github.com/googleapis/google-cloud-rust/tree/main"
10+
keywords = ["gcp", "google-cloud", "google-cloud-rust", "sdk"]
11+
categories = ["network-programming"]
12+
rust-version = "1.85.0"
13+
14+
[workspace.dependencies]
15+
async-trait = "0.1"
16+
bytes = "1"
17+
gax = { version = "1", package = "google-cloud-gax" }
18+
iam_v1 = { version = "1", package = "google-cloud-iam-v1" }
19+
location = { version = "1", package = "google-cloud-location" }
20+
reqwest = "0.12"
21+
serde = "1"
22+
serde_json = "1"
23+
serde_with = "3"
24+
time = "0.3"
25+
tokio-test = "0.4"
26+
wkt = { version = "1", package = "google-cloud-wkt" }

0 commit comments

Comments
 (0)