Skip to content

Commit 5c17ce1

Browse files
authored
Merge pull request #1 from datachainlab/enable-target-env-check
Enable `target_env` check for links Signed-off-by: Jun Kimura <junkxdev@gmail.com>
2 parents a665b62 + 3e6fbdb commit 5c17ce1

File tree

6 files changed

+48
-47
lines changed

6 files changed

+48
-47
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ fmt-check:
1515
.PHONY: clippy
1616
clippy:
1717
@find . -name Cargo.toml -not -path "./target/*" -exec dirname {} \; | while read dir; do \
18-
echo "Running clippy on $$dir..."; \
19-
if echo "$$dir" | grep -E -q "(enclave$$|sgx-ert)"; then \
20-
echo "Skipping $$dir"; \
18+
if echo "$$dir" | grep -E -q "(enclave$$|sgx-ert|sgx-trts|sgx-tcrypto|sgx-tse|sgx-tseal)"; then \
19+
echo "Running clippy on $$dir with SGX target..."; \
20+
TARGET_SPEC="$$(pwd)/unit-test/enclave/x86_64-unknown-unknown-sgx.json"; \
21+
(cd "$$dir" && cargo clippy -Z build-std=core,alloc --target="$$TARGET_SPEC" --all-features -- -D warnings) || exit 1; \
2122
else \
23+
echo "Running clippy on $$dir..."; \
2224
(cd "$$dir" && cargo clippy --all-targets --all-features -- -D warnings) || exit 1; \
2325
fi; \
2426
done

samples/hello-rust/enclave/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub extern "C" fn ecall_sample(
3333
};
3434

3535
// Process the input (example: echo back with prefix)
36-
let result = format!("Hello from enclave: {}", input_string);
36+
let result = format!("Hello from enclave: {input_string}");
3737
let result_bytes = result.as_bytes();
3838

3939
// Check if output buffer is large enough

sgx-types/src/function.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::*;
2222
// Constants from sgx-trts
2323
pub const LAYOUT_ENTRY_NUM: usize = 43;
2424

25-
#[cfg(feature = "tstdc")]
25+
#[cfg(all(feature = "tstdc", target_env = "sgx"))]
2626
#[link(name = "sgx_tstdc", kind = "static")]
2727
extern "C" {
2828
//
@@ -107,7 +107,7 @@ extern "C" {
107107
pub fn sgx_alloc_rsrv_mem_ex(desired_addr: *const c_void, length: size_t) -> *mut c_void;
108108
}
109109

110-
#[cfg(feature = "tservice")]
110+
#[cfg(all(feature = "tservice", target_env = "sgx"))]
111111
#[cfg_attr(
112112
not(feature = "simulation"),
113113
link(name = "sgx_tservice", kind = "static")
@@ -278,7 +278,7 @@ extern "C" {
278278
) -> *mut c_void;
279279
}
280280

281-
#[cfg(feature = "tcrypto")]
281+
#[cfg(all(feature = "tcrypto", target_env = "sgx"))]
282282
#[link(name = "sgx_tcrypto", kind = "static")]
283283
extern "C" {
284284
//
@@ -619,7 +619,7 @@ extern "C" {
619619
) -> sgx_status_t;
620620
}
621621

622-
#[cfg(feature = "tkey_exchange")]
622+
#[cfg(all(feature = "tkey_exchange", target_env = "sgx"))]
623623
#[link(name = "sgx_tkey_exchange", kind = "static")]
624624
extern "C" {
625625
//
@@ -650,7 +650,7 @@ extern "C" {
650650
) -> sgx_status_t;
651651
}
652652

653-
#[cfg(feature = "trts")]
653+
#[cfg(all(feature = "trts", target_env = "sgx"))]
654654
#[cfg_attr(not(feature = "simulation"), link(name = "sgx_trts", kind = "static"))]
655655
#[cfg_attr(feature = "simulation", link(name = "sgx_trts_sim", kind = "static"))]
656656
extern "C" {
@@ -787,7 +787,7 @@ pub struct thread_data_t {
787787
}
788788

789789
/* intel sgx sdk 2.18 */
790-
#[cfg(feature = "mm")]
790+
#[cfg(all(feature = "mm", target_env = "sgx"))]
791791
#[link(name = "sgx_mm", kind = "static")]
792792
extern "C" {
793793
pub fn sgx_mm_alloc(
@@ -813,7 +813,7 @@ extern "C" {
813813
pub fn sgx_mm_modify_type(addr: *const c_void, length: size_t, page_type: int32_t) -> int32_t;
814814
}
815815

816-
#[cfg(feature = "epid")]
816+
#[cfg(all(feature = "epid", not(target_env = "sgx")))]
817817
#[link(name = "sgx_epid", kind = "dylib")]
818818
extern "C" {
819819
//
@@ -863,7 +863,7 @@ extern "C" {
863863
) -> sgx_status_t;
864864
}
865865

866-
#[cfg(feature = "launch")]
866+
#[cfg(all(feature = "launch", not(target_env = "sgx")))]
867867
#[link(name = "sgx_launch", kind = "dylib")]
868868
extern "C" {
869869
//
@@ -880,7 +880,7 @@ extern "C" {
880880
) -> sgx_status_t;
881881
}
882882

883-
#[cfg(feature = "platform")]
883+
#[cfg(all(feature = "platform", not(target_env = "sgx")))]
884884
#[link(name = "sgx_platform", kind = "dylib")]
885885
extern "C" {
886886
//
@@ -889,7 +889,7 @@ extern "C" {
889889
pub fn sgx_get_ps_cap(p_sgx_ps_cap: *mut sgx_ps_cap_t) -> sgx_status_t;
890890
}
891891

892-
#[cfg(feature = "quote_ex")]
892+
#[cfg(all(feature = "quote_ex", not(target_env = "sgx")))]
893893
#[link(name = "sgx_quote_ex", kind = "dylib")]
894894
extern "C" {
895895
//
@@ -931,7 +931,7 @@ extern "C" {
931931
) -> sgx_status_t;
932932
}
933933

934-
#[cfg(feature = "uae_service")]
934+
#[cfg(all(feature = "uae_service", not(target_env = "sgx")))]
935935
#[link(name = "sgx_uae_service", kind = "dylib")]
936936
extern "C" {
937937
//
@@ -943,7 +943,7 @@ extern "C" {
943943
//
944944
}
945945

946-
#[cfg(feature = "ukey_exchange")]
946+
#[cfg(all(feature = "ukey_exchange", not(target_env = "sgx")))]
947947
#[link(name = "sgx_ukey_exchange", kind = "dylib")]
948948
extern "C" {
949949
//
@@ -989,7 +989,7 @@ extern "C" {
989989
) -> sgx_status_t;
990990
}
991991

992-
#[cfg(feature = "urts")]
992+
#[cfg(all(feature = "urts", not(target_env = "sgx")))]
993993
#[cfg_attr(not(feature = "simulation"), link(name = "sgx_urts", kind = "dylib"))]
994994
#[cfg_attr(feature = "simulation", link(name = "sgx_urts_sim", kind = "dylib"))]
995995
extern "C" {
@@ -1055,7 +1055,7 @@ extern "C" {
10551055
}
10561056

10571057
/* intel sgx sdk 1.9 */
1058-
#[cfg(feature = "tprotected_fs")]
1058+
#[cfg(all(feature = "tprotected_fs", target_env = "sgx"))]
10591059
#[link(name = "sgx_tprotected_fs", kind = "static")]
10601060
extern "C" {
10611061
//
@@ -1094,7 +1094,7 @@ extern "C" {
10941094
}
10951095

10961096
/* intel sgx sdk 2.0 */
1097-
#[cfg(feature = "capable")]
1097+
#[cfg(all(feature = "capable", not(target_env = "sgx")))]
10981098
#[link(name = "sgx_capable", kind = "dylib")]
10991099
extern "C" {
11001100
//
@@ -1105,7 +1105,7 @@ extern "C" {
11051105
pub fn sgx_cap_get_status(sgx_device_status: *mut sgx_device_status_t) -> sgx_status_t;
11061106
}
11071107

1108-
#[cfg(feature = "pce_wrapper")]
1108+
#[cfg(all(feature = "pce_wrapper", not(target_env = "sgx")))]
11091109
#[link(name = "sgx_pce_wrapper", kind = "dylib")]
11101110
extern "C" {
11111111
//
@@ -1144,7 +1144,7 @@ extern "C" {
11441144
) -> sgx_pce_error_t;
11451145
}
11461146

1147-
#[cfg(feature = "dcap_ql")]
1147+
#[cfg(all(feature = "dcap_ql", not(target_env = "sgx")))]
11481148
#[link(name = "sgx_dcap_ql", kind = "dylib")]
11491149
extern "C" {
11501150
//
@@ -1167,7 +1167,7 @@ extern "C" {
11671167
) -> sgx_quote3_error_t;
11681168
}
11691169

1170-
#[cfg(feature = "dcap_quoteprov")]
1170+
#[cfg(all(feature = "dcap_quoteprov", not(target_env = "sgx")))]
11711171
#[link(name = "dcap_quoteprov", kind = "dylib")]
11721172
extern "C" {
11731173
//
@@ -1242,7 +1242,7 @@ extern "C" {
12421242
pub fn sgx_qpl_global_cleanup() -> sgx_quote3_error_t;
12431243
}
12441244

1245-
#[cfg(feature = "default_qcnl_wrapper")]
1245+
#[cfg(all(feature = "default_qcnl_wrapper", not(target_env = "sgx")))]
12461246
#[link(name = "sgx_default_qcnl_wrapper", kind = "dylib")]
12471247
extern "C" {
12481248
//
@@ -1326,7 +1326,7 @@ extern "C" {
13261326
pub fn sgx_qcnl_global_cleanup() -> sgx_qcnl_error_t;
13271327
}
13281328

1329-
#[cfg(feature = "dcap_quoteverify")]
1329+
#[cfg(all(feature = "dcap_quoteverify", not(target_env = "sgx")))]
13301330
#[link(name = "dcap_quoteverify", kind = "dylib")]
13311331
extern "C" {
13321332
//
@@ -1423,7 +1423,7 @@ extern "C" {
14231423
}
14241424

14251425
/* intel DCAP 1.7 */
1426-
#[cfg(feature = "dcap_tvl")]
1426+
#[cfg(all(feature = "dcap_tvl", target_env = "sgx"))]
14271427
#[link(name = "sgx_dcap_tvl", kind = "static")]
14281428
extern "C" {
14291429
//
@@ -1443,7 +1443,7 @@ extern "C" {
14431443
}
14441444

14451445
/* intel DCAP 1.15 */
1446-
#[cfg(feature = "tdx_attest")]
1446+
#[cfg(all(feature = "tdx_attest", target_env = "sgx"))]
14471447
#[link(name = "libtdx_attest", kind = "dylib")]
14481448
extern "C" {
14491449
//
@@ -1475,7 +1475,7 @@ extern "C" {
14751475
}
14761476

14771477
/* intel sgx sdk 2.16 */
1478-
#[cfg(feature = "ttls")]
1478+
#[cfg(all(feature = "ttls", target_env = "sgx"))]
14791479
#[link(name = "sgx_ttls", kind = "static")]
14801480
extern "C" {
14811481
//
@@ -1504,7 +1504,7 @@ extern "C" {
15041504
}
15051505

15061506
/* intel sgx sdk 2.16 */
1507-
#[cfg(feature = "utls")]
1507+
#[cfg(all(feature = "utls", not(target_env = "sgx")))]
15081508
#[link(name = "sgx_utls", kind = "dylib")]
15091509
extern "C" {
15101510
//

unit-test/enclave/src/test_crate.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ use crate::utils::*;
22
use crate::TestResult;
33
use alloc::string::String;
44

5-
static HASH_TEST_VEC: &'static [&'static str] = &[
6-
&"abc",
7-
&"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
8-
&"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
5+
static HASH_TEST_VEC: &[&str] = &[
6+
"abc",
7+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
8+
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
99
];
1010

11-
static HASH_SHA256_TRUTH: &'static [&'static str] = &[
12-
&"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
13-
&"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
14-
&"cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1",
11+
static HASH_SHA256_TRUTH: &[&str] = &[
12+
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
13+
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
14+
"cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1",
1515
];
1616

1717
pub fn test_sha2_crate() -> TestResult {

unit-test/enclave/src/test_crypto.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ use crate::TestResult;
2020
use alloc::string::String;
2121
use sgx_tcrypto::*;
2222

23-
static HASH_TEST_VEC: &'static [&'static str] = &[
24-
&"abc",
25-
&"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
26-
&"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
23+
static HASH_TEST_VEC: &[&str] = &[
24+
"abc",
25+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
26+
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
2727
];
2828

29-
static HASH_SHA256_TRUTH: &'static [&'static str] = &[
30-
&"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
31-
&"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
32-
&"cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1",
29+
static HASH_SHA256_TRUTH: &[&str] = &[
30+
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
31+
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
32+
"cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1",
3333
];
3434

3535
pub fn test_rsgx_sha256_slice() -> TestResult {

unit-test/enclave/src/test_seal.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ pub fn test_seal_unseal() -> TestResult {
5252

5353
unsafe impl ContiguousMemory for RandData {}
5454

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

5857
// Use sgx random instead of StdRng
5958
rsgx_read_rand(&mut data.rand).map_err(|_| "Failed to generate random data")?;
@@ -105,7 +104,7 @@ pub fn test_mac_aadata_slice() -> TestResult {
105104
if unsealed_data.get_decrypt_txt() != &text {
106105
return Err("Decrypted text verification failed");
107106
}
108-
if unsealed_data.get_additional_txt() != &aad_data {
107+
if unsealed_data.get_additional_txt() != aad_data {
109108
return Err("AAD verification failed");
110109
}
111110

0 commit comments

Comments
 (0)