Skip to content

Commit 7997ae6

Browse files
committed
fix clippy run support
Signed-off-by: Jun Kimura <junkxdev@gmail.com>
1 parent fef1c31 commit 7997ae6

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fmt-check:
1515
.PHONY: clippy
1616
clippy:
1717
@find . -name Cargo.toml -not -path "./target/*" -exec dirname {} \; | while read dir; do \
18-
if echo "$$dir" | grep -E -q "(enclave$$|sgx-ert|sgx-trts|sgx-tcrypto|sgx-tse|sgx-tseal)"; then \
18+
if echo "$$dir" | grep -E -q "(enclave$$)"; then \
1919
echo "Running clippy on $$dir with SGX target..."; \
2020
TARGET_SPEC="$$(pwd)/unit-test/enclave/x86_64-unknown-unknown-sgx.json"; \
2121
(cd "$$dir" && cargo clippy -Z build-std=core,alloc --target="$$TARGET_SPEC" --all-features -- -D warnings) || exit 1; \

sgx-ert/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ pub use sgx_types;
2222
#[global_allocator]
2323
static ALLOC: sgx_alloc::System = sgx_alloc::System;
2424

25-
#[cfg(feature = "panic-handler")]
25+
#[cfg(all(feature = "panic-handler", target_env = "sgx"))]
2626
#[allow(unused_variables)]
2727
#[panic_handler]
2828
fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
2929
sgx_abort();
3030
}
3131

32+
#[cfg(target_env = "sgx")]
3233
#[lang = "eh_personality"]
3334
fn rust_eh_personality() {}
3435

@@ -65,6 +66,7 @@ pub fn take_alloc_error_hook() -> fn(Layout) {
6566

6667
fn default_alloc_error_hook(_layout: Layout) {}
6768

69+
#[cfg(target_env = "sgx")]
6870
#[alloc_error_handler]
6971
pub fn rust_oom(layout: Layout) -> ! {
7072
let hook = HOOK.load(Ordering::SeqCst);
@@ -77,6 +79,7 @@ pub fn rust_oom(layout: Layout) -> ! {
7779
sgx_abort();
7880
}
7981

82+
#[cfg(target_env = "sgx")]
8083
fn sgx_abort() -> ! {
8184
unsafe { sgx_types::abort() }
8285
}

sgx-types/src/function.rs

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

25-
#[cfg(all(feature = "tstdc", target_env = "sgx"))]
26-
#[link(name = "sgx_tstdc", kind = "static")]
25+
#[cfg(feature = "tstdc")]
26+
#[cfg_attr(target_env = "sgx", link(name = "sgx_tstdc", kind = "static"))]
2727
extern "C" {
2828
//
2929
// sgx_cpuid.h
@@ -107,13 +107,13 @@ 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(all(feature = "tservice", target_env = "sgx"))]
110+
#[cfg(feature = "tservice")]
111111
#[cfg_attr(
112-
not(feature = "simulation"),
112+
all(target_env = "sgx", not(feature = "simulation")),
113113
link(name = "sgx_tservice", kind = "static")
114114
)]
115115
#[cfg_attr(
116-
feature = "simulation",
116+
all(target_env = "sgx", feature = "simulation"),
117117
link(name = "sgx_tservice_sim", kind = "static")
118118
)]
119119
extern "C" {
@@ -278,8 +278,8 @@ extern "C" {
278278
) -> *mut c_void;
279279
}
280280

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

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

653-
#[cfg(all(feature = "trts", target_env = "sgx"))]
654-
#[cfg_attr(not(feature = "simulation"), link(name = "sgx_trts", kind = "static"))]
655-
#[cfg_attr(feature = "simulation", link(name = "sgx_trts_sim", kind = "static"))]
653+
#[cfg(feature = "trts")]
654+
#[cfg_attr(
655+
all(target_env = "sgx", not(feature = "simulation")),
656+
link(name = "sgx_trts", kind = "static")
657+
)]
658+
#[cfg_attr(
659+
all(target_env = "sgx", feature = "simulation"),
660+
link(name = "sgx_trts_sim", kind = "static")
661+
)]
656662
extern "C" {
657663

658664
pub fn abort() -> !;
@@ -787,8 +793,8 @@ pub struct thread_data_t {
787793
}
788794

789795
/* intel sgx sdk 2.18 */
790-
#[cfg(all(feature = "mm", target_env = "sgx"))]
791-
#[link(name = "sgx_mm", kind = "static")]
796+
#[cfg(feature = "mm")]
797+
#[cfg_attr(target_env = "sgx", link(name = "sgx_mm", kind = "static"))]
792798
extern "C" {
793799
pub fn sgx_mm_alloc(
794800
addr: *const c_void,
@@ -1055,8 +1061,8 @@ extern "C" {
10551061
}
10561062

10571063
/* intel sgx sdk 1.9 */
1058-
#[cfg(all(feature = "tprotected_fs", target_env = "sgx"))]
1059-
#[link(name = "sgx_tprotected_fs", kind = "static")]
1064+
#[cfg(feature = "tprotected_fs")]
1065+
#[cfg_attr(target_env = "sgx", link(name = "sgx_tprotected_fs", kind = "static"))]
10601066
extern "C" {
10611067
//
10621068
// sgx_tprotected_fs.h
@@ -1423,8 +1429,8 @@ extern "C" {
14231429
}
14241430

14251431
/* intel DCAP 1.7 */
1426-
#[cfg(all(feature = "dcap_tvl", target_env = "sgx"))]
1427-
#[link(name = "sgx_dcap_tvl", kind = "static")]
1432+
#[cfg(feature = "dcap_tvl")]
1433+
#[cfg_attr(target_env = "sgx", link(name = "sgx_dcap_tvl", kind = "static"))]
14281434
extern "C" {
14291435
//
14301436
// sgx_dcap_tvl.h
@@ -1443,8 +1449,8 @@ extern "C" {
14431449
}
14441450

14451451
/* intel DCAP 1.15 */
1446-
#[cfg(all(feature = "tdx_attest", target_env = "sgx"))]
1447-
#[link(name = "libtdx_attest", kind = "dylib")]
1452+
#[cfg(feature = "tdx_attest")]
1453+
#[cfg_attr(target_env = "sgx", link(name = "libtdx_attest", kind = "dylib"))]
14481454
extern "C" {
14491455
//
14501456
// tdx_attes.h
@@ -1475,8 +1481,8 @@ extern "C" {
14751481
}
14761482

14771483
/* intel sgx sdk 2.16 */
1478-
#[cfg(all(feature = "ttls", target_env = "sgx"))]
1479-
#[link(name = "sgx_ttls", kind = "static")]
1484+
#[cfg(feature = "ttls")]
1485+
#[cfg_attr(target_env = "sgx", link(name = "sgx_ttls", kind = "static"))]
14801486
extern "C" {
14811487
//
14821488
// sgx_ttls.h

0 commit comments

Comments
 (0)