Skip to content

Commit 5ca7d87

Browse files
authored
Merge pull request #2 from datachainlab/fix-app-build
Fix to return correct target directory path Signed-off-by: Jun Kimura <junkxdev@gmail.com>
2 parents 5c17ce1 + 029db16 commit 5ca7d87

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ clippy:
2626
done
2727

2828
.PHONY: check
29-
check: fmt clippy
29+
check: fmt-check clippy
3030

3131
.PHONY: test
3232
test:

sgx-build/src/lib.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,35 @@ pub struct SgxBuilder {
9696
impl 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

unit-test/enclave/src/test_seal.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ pub fn test_seal_unseal() -> TestResult {
5252

5353
unsafe impl ContiguousMemory for RandData {}
5454

55-
let mut data = RandData { key: 0x1234, ..Default::default() };
55+
let mut data = RandData {
56+
key: 0x1234,
57+
..Default::default()
58+
};
5659

5760
// Use sgx random instead of StdRng
5861
rsgx_read_rand(&mut data.rand).map_err(|_| "Failed to generate random data")?;

0 commit comments

Comments
 (0)