Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to skip experimental_allow_proto3_optional #1424

Open
azharimad opened this issue Feb 21, 2025 · 3 comments
Open

how to skip experimental_allow_proto3_optional #1424

azharimad opened this issue Feb 21, 2025 · 3 comments

Comments

@azharimad
Copy link

azharimad commented Feb 21, 2025

This is how to resolved experimental_allow_proto3

Install
sudo apt update && sudo apt install -y protobuf-compiler

after modify build.rs run cargo with cargo run -r -- start --env beta

modify build.rs to this

use prost_build::Config;
use std::{env, error::Error, fs, path::Path, process::Command};

fn main() -> Result<(), Box<dyn Error>> {
    // Tell cargo to recompile if any of these files change
    println!("cargo:rerun-if-changed=proto/orchestrator.proto");
    println!("cargo:rerun-if-changed=build.rs");

    let proto_path = Path::new("proto/orchestrator.proto");

    // Print current directory
    println!("Current dir: {:?}", env::current_dir()?);

    // Check if proto file exists
    if !proto_path.exists() {
        println!("Error: Proto file not found at {:?}", proto_path);
        return Err("Proto file not found".into());
    }
    println!("Found proto file at {:?}", proto_path.canonicalize()?);

    let out_dir = "src/proto";

    // Check if protoc is installed and accessible
    let output = Command::new("which")
        .arg("protoc")
        .output()
        .expect("Failed to execute command");

    if output.status.success() {
        println!("protoc is installed and accessible.");
    } else {
        println!("Error: protoc is not installed or not in PATH.");
        return Err("protoc not found".into());
    }

    // Ensure the output directory exists
    if !Path::new(out_dir).exists() {
        fs::create_dir_all(out_dir)?;
        println!("Created output directory: {}", out_dir);
    } else {
        println!("Output directory exists: {}", out_dir);
    }

    // Configure prost_build and compile .proto files
    let mut config = Config::new();
    config.out_dir(out_dir);

    match config
        .protoc_arg("--experimental_allow_proto3_optional") // Tambahkan flag ini
        .compile_protos(&["proto/orchestrator.proto"], &["proto"])
    {
        Ok(_) => println!("Successfully compiled protobuf files."),
        Err(e) => {
            println!("Error compiling protobuf files: {}", e);
            return Err(Box::new(e));
        }
    }

    // Print the generated file path
    let generated_file_path = format!("{}/orchestrator.rs", out_dir);
    if Path::new(&generated_file_path).exists() {
        println!("Generated file exists: {}", generated_file_path);
    } else {
        println!("Error: Generated file does not exist at {}", generated_file_path);
        return Err("Generated file not found".into());
    }

    Ok(())
}
@avarice27
Copy link

bang udh coba edit sm di run msh ttp error gini napa y?
error: failed to run custom build command for nexus-network v0.5.5 (/home/rafi/.nexus/network-api/clients/cli)

Caused by:
process didn't exit successfully: /home/rafi/.nexus/network-api/clients/cli/target/release/build/nexus-network-ffaee377ad2254b7/build-script-build (exit status: 1)
--- stdout
cargo:rerun-if-changed=proto/orchestrator.proto
cargo:rerun-if-changed=build.rs
Current dir: "/home/rafi/.nexus/network-api/clients/cli"
Looking for proto file at: "/home/rafi/.nexus/network-api/clients/cli/proto/orchestrator.proto"
protoc is installed and accessible.
Output directory src/proto exists.
Error compiling protobuf files: protoc failed: orchestrator.proto: This file contains proto3 optional fields, but --experimental_allow_proto3_optional was not set.

Error: protoc failed: orchestrator.proto: This file contains proto3 optional fields, but --experimental_allow_proto3_optional was not set.

--- stderr
Error: Custom { kind: Other, error: "protoc failed: orchestrator.proto: This file contains proto3 optional fields, but --experimental_allow_proto3_optional was not set.\n" }
warning: build failed, waiting for other jobs to finish...

@azharimad
Copy link
Author

di .nexus/network-api/clients/cli/src/proto
rename nexus.orchestrator.rs jadi orchestrator.rs

@avarice27
Copy link

isi file orchestrator apa y bang? w cb buka no such file or directory soalnya

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

No branches or pull requests

2 participants