@@ -96,12 +96,35 @@ pub struct SgxBuilder {
9696impl SgxBuilder {
9797 /// Get the target directory for EDL artifacts
9898 fn get_edl_target_dir ( ) -> PathBuf {
99- let target_base = if let Ok ( target_dir) = env:: var ( "CARGO_TARGET_DIR" ) {
100- PathBuf :: from ( target_dir)
101- } else {
102- PathBuf :: from ( "target" )
103- } ;
104- target_base. join ( "edl" )
99+ // First, try CARGO_TARGET_DIR which is explicitly set
100+ if let Ok ( target_dir) = env:: var ( "CARGO_TARGET_DIR" ) {
101+ return PathBuf :: from ( target_dir) . join ( "edl" ) ;
102+ }
103+
104+ // Otherwise, require OUT_DIR to be set (should always be set in build.rs context)
105+ let out_dir = env:: var ( "OUT_DIR" )
106+ . expect ( "OUT_DIR not set. This function should only be called from build.rs" ) ;
107+
108+ let out_path = PathBuf :: from ( out_dir) ;
109+
110+ // Find the target directory by looking for a directory named "target"
111+ // while traversing up the directory tree
112+ let mut current_dir = out_path. as_path ( ) ;
113+ loop {
114+ if let Some ( file_name) = current_dir. file_name ( ) {
115+ if file_name == "target" {
116+ return current_dir. join ( "edl" ) ;
117+ }
118+ }
119+
120+ match current_dir. parent ( ) {
121+ Some ( parent) => current_dir = parent,
122+ None => panic ! (
123+ "Could not find 'target' directory in OUT_DIR path: {}" ,
124+ out_path. display( )
125+ ) ,
126+ }
127+ }
105128 }
106129
107130 /// Create a new EnclaveBuilder with default settings from environment
0 commit comments