Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix include paths for wasm build #395

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jobs:
with:
files: lcov.info

# This job ensures that the specified crates are able to build without alloc. By proxy this also ensures that the
# This job ensures that the specified crates are able to build without alloc. By proxy this also ensures that they
# build with no_std
build-no-alloc:
runs-on: ubuntu-22.04
Expand All @@ -212,6 +212,7 @@ jobs:
- thumbv8m.main-none-eabi
- aarch64-linux-android
- aarch64-apple-ios
- wasm32-unknown-unknown
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
Expand All @@ -220,17 +221,14 @@ jobs:
targets: ${{ matrix.target }},x86_64-unknown-linux-gnu
components: rust-src
- uses: r7kamura/rust-problem-matchers@v1
- name: Build types with no alloc crate on various platfroms
# Some notes on this build command:
# - The vendored headers are used to get the necessary DCAP headers
# - The vendored `tlibc` is used to get a compilable `time.h` for the target.
# - In the unlikely event that the target was installed with rustup, this would error out with
# duplicate core symbols due to `-Z build-std=core`.
- name: Build types with no alloc crate on various platforms
# In the unlikely event that the target was installed with rustup, this would error out with duplicate core
# symbols due to `-Z build-std=core`.
run: |
cargo metadata --no-deps --format-version=1 | \
jq -r '.packages[].name' | \
grep -e types | \
xargs -n1 sh -c 'CFLAGS="-isystem${GITHUB_WORKSPACE}/core/build/headers -isystem${GITHUB_WORKSPACE}/core/build/headers/tlibc" cargo +nightly-2022-12-13 build -Z build-std=core --target ${{ matrix.target }} -p $0 --locked || exit 255'
xargs -n1 sh -c 'cargo +nightly-2022-12-13 build -Z build-std=core --target ${{ matrix.target }} -p $0 --locked || exit 255'

notify:
runs-on: ubuntu-latest
Expand Down
33 changes: 12 additions & 21 deletions core/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@
/// Returns a builder configured with the defaults for using bindgen with the
/// SGX libraries.
pub fn sgx_builder() -> Builder {
let include_path = sgx_include_string();

let builder = Builder::default()
let mut builder = Builder::default()

Check warning on line 67 in core/build/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

core/build/src/lib.rs#L67

Added line #L67 was not covered by tests
.derive_copy(false)
.derive_debug(false)
.default_enum_style(EnumVariation::NewType {
Expand All @@ -77,10 +75,13 @@
.use_core()
.ctypes_prefix("core::ffi")
.allowlist_recursively(false)
.clang_args(env_c_flags())
.clang_arg(format!("-I{include_path}"));
.clang_args(env_c_flags());

Check warning on line 78 in core/build/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

core/build/src/lib.rs#L78

Added line #L78 was not covered by tests

cargo_emit::rerun_if_changed!(include_path);
for include_path in vendored_include_paths() {
let include_path = include_path.display();
builder = builder.clang_arg(format!("-I{include_path}"));
cargo_emit::rerun_if_changed!(include_path);
}

Check warning on line 84 in core/build/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

core/build/src/lib.rs#L80-L84

Added lines #L80 - L84 were not covered by tests

builder
}
Expand Down Expand Up @@ -268,22 +269,12 @@
/// scattered about the repo.
const CARGO_MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");

/// Return the SGX include path
/// Return the SGX include paths
///
/// Will first attempt to look at the environment variable `SGX_SDK`, if that
/// isn't present then the "headers" directory of this crate will be used.
pub fn sgx_include_dir() -> PathBuf {
PathBuf::from(CARGO_MANIFEST_DIR).join("headers")
}

/// Return the SGX include path as a string.
///
/// Calls sgx_include_dir() and converts to a string.
pub fn sgx_include_string() -> String {
sgx_include_dir()
.to_str()
.expect("SGX_SDK contained invalid UTF-8 that wasn't caught by rust")
.to_owned()
/// The paths to the vendored headers are always used.
fn vendored_include_paths() -> Vec<PathBuf> {
let headers = PathBuf::from(CARGO_MANIFEST_DIR).join("headers");
vec![headers.join("tlibc"), headers]

Check warning on line 277 in core/build/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

core/build/src/lib.rs#L275-L277

Added lines #L275 - L277 were not covered by tests
}

/// Return the SGX library path.
Expand Down
Loading