1-
21use std:: { env, path:: PathBuf , process:: Command } ;
32
43const GO_SRC : & str = "./gnark/verifier.go" ;
@@ -9,83 +8,44 @@ const CIRCOM_SRC: &str = "./circom/verifier.go";
98const CIRCOM_OUT : & str = "libcircomverifier.a" ;
109const CIRCOM_LIB : & str = "circomverifier" ;
1110
12- fn ensure_go_dependencies ( ) {
13- // Check if there's a go.mod in the current directory or parent directories
14- let current_dir = env:: current_dir ( ) . expect ( "Failed to get current directory" ) ;
15- println ! ( "Build script running in: {:?}" , current_dir) ;
11+ fn main ( ) {
12+ let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
1613
17- // Try to find go.mod files
18- let possible_dirs = vec ! [
19- current_dir. clone( ) ,
20- current_dir. parent( ) . unwrap_or( & current_dir) . to_path_buf( ) ,
21- current_dir. parent( ) . unwrap_or( & current_dir) . parent( ) . unwrap_or( & current_dir) . to_path_buf( ) ,
22- ] ;
14+ // Fix the missing dependency issue
15+ let mut get_cmd = Command :: new ( "go" ) ;
16+ get_cmd. arg ( "get" )
17+ . arg ( "github.com/yetanotherco/go-circom-prover-verifier/[email protected] " ) ; 2318
24- for dir in possible_dirs {
25- let go_mod_path = dir. join ( "go.mod" ) ;
26- if go_mod_path. exists ( ) {
27- println ! ( "Found go.mod in: {:?}" , dir) ;
28-
29- // Run go mod tidy to ensure all dependencies are properly resolved
30- // let mut tidy_cmd = Command::new("go");
31- // tidy_cmd.arg("mod").arg("tidy").current_dir(&dir);
32-
33- // let tidy_output = tidy_cmd.output().expect("Failed to run go mod tidy");
34- // if !tidy_output.status.success() {
35- // eprintln!("go mod tidy failed in {:?}: {}", dir, String::from_utf8_lossy(&tidy_output.stderr));
36- // } else {
37- // println!("Successfully ran go mod tidy in {:?}", dir);
38- // }
39-
40- // Run go mod download to ensure all modules are cached
41- let mut cmd = Command :: new ( "go" ) ;
42- cmd. arg ( "mod" ) . arg ( "download" ) . current_dir ( & dir) ;
43-
44- let output = cmd. output ( ) . expect ( "Failed to run go mod download" ) ;
45- if !output. status . success ( ) {
46- eprintln ! ( "go mod download failed in {:?}: {}" , dir, String :: from_utf8_lossy( & output. stderr) ) ;
47- } else {
48- println ! ( "Successfully ran go mod download in {:?}" , dir) ;
49- }
50-
51- break ;
52- }
53- }
54- }
55-
56- fn build_go_library ( src : & str , out : & str , out_dir : & PathBuf ) {
57- println ! ( "Building Go library: {} -> {}" , src, out) ;
19+ let _ = get_cmd. output ( ) ; // Run but don't fail if it has issues
5820
21+ // Build gnark library
5922 let mut go_build = Command :: new ( "go" ) ;
6023 go_build
6124 . arg ( "build" )
6225 . arg ( "-buildmode=c-archive" )
6326 . arg ( "-o" )
64- . arg ( out_dir. join ( out ) )
65- . arg ( src ) ;
27+ . arg ( out_dir. join ( GO_OUT ) )
28+ . arg ( GO_SRC ) ;
6629
67- let output = go_build. output ( ) . expect ( "Failed to execute Go build command" ) ;
68- if !output. status . success ( ) {
69- eprintln ! ( "Go build failed for {}: {}" , src, String :: from_utf8_lossy( & output. stderr) ) ;
70- panic ! ( "Go build failed for {}" , src) ;
71- }
72- println ! ( "Successfully built {}" , src) ;
73- }
30+ go_build. status ( ) . expect ( "Go build failed" ) ;
7431
75- fn main ( ) {
76- let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
77-
78- // Ensure Go dependencies are available
79- ensure_go_dependencies ( ) ;
32+ // Build circom library
33+ let mut circom_build = Command :: new ( "go" ) ;
34+ circom_build
35+ . arg ( "build" )
36+ . arg ( "-buildmode=c-archive" )
37+ . arg ( "-o" )
38+ . arg ( out_dir. join ( CIRCOM_OUT ) )
39+ . arg ( CIRCOM_SRC ) ;
8040
81- // Build both Go libraries
82- build_go_library ( GO_SRC , GO_OUT , & out_dir) ;
83- build_go_library ( CIRCOM_SRC , CIRCOM_OUT , & out_dir) ;
41+ let output = circom_build. output ( ) . expect ( "Failed to execute Circom build command" ) ;
42+ if !output. status . success ( ) {
43+ eprintln ! ( "Circom build failed: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
44+ panic ! ( "Circom build failed" ) ;
45+ }
8446
8547 println ! ( "cargo:rerun-if-changed={}" , GO_SRC ) ;
8648 println ! ( "cargo:rerun-if-changed={}" , CIRCOM_SRC ) ;
87- println ! ( "cargo:rerun-if-changed=go.mod" ) ;
88- println ! ( "cargo:rerun-if-changed=go.sum" ) ;
8949 println ! (
9050 "cargo:rustc-link-search=native={}" ,
9151 out_dir. to_str( ) . unwrap( )
0 commit comments