build.rs 1.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Only regenerate if the proto file changes
    println!("cargo:rerun-if-changed=src/proto/sglang_scheduler.proto");

    // Configure protobuf compilation with custom settings
    let config = prost_build::Config::new();

    // Skip serde for types that use prost_types::Struct
    // These cause conflicts and we don't need serde for all generated types

    // Configure tonic-build for gRPC code generation
    tonic_build::configure()
        // Generate both client and server code
        .build_server(true)
        .build_client(true)
16
17
        // Add protoc arguments for proto3 optional support
        .protoc_arg("--experimental_allow_proto3_optional")
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
        // Add a module-level attribute for documentation and clippy warnings
        .server_mod_attribute(
            "sglang.grpc.scheduler",
            "#[allow(unused, clippy::mixed_attributes_style)]",
        )
        .client_mod_attribute(
            "sglang.grpc.scheduler",
            "#[allow(unused, clippy::mixed_attributes_style)]",
        )
        // Compile the proto file with the custom config
        .compile_protos_with_config(
            config,
            &["src/proto/sglang_scheduler.proto"],
            &["src/proto"],
        )?;

    println!("cargo:warning=Protobuf compilation completed successfully");

    Ok(())
}