Skip to content

Commit

Permalink
Ensure types crates don't use alloc with CI (#179)
Browse files Browse the repository at this point in the history
Update the crates to build with the `thumbv7m-none-eabi` target using
only the `core` crate from std
  • Loading branch information
nick-mobilecoin authored Oct 25, 2022
2 parents 0a6a190 + 093d8d8 commit d7b4028
Show file tree
Hide file tree
Showing 39 changed files with 3,374 additions and 7 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,32 @@ jobs:
with:
files: lcov.info

build-no-alloc:
runs-on: ubuntu-20.04
needs:
- "rustfmt"
- "markdown-lint"
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- run: rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
- uses: r7kamura/rust-problem-matchers@v1
- name: Build types with no alloc crate
# 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 `thumbv7m-none-eabi` 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 build -Z build-std=core --target thumbv7m-none-eabi -p $0 || exit 255'
notify:
runs-on: ubuntu-latest
if: failure() && ${{ github.event_name }} == 'push'
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ exclude = [
"test_enclave",
]

# We need to explicitly specify resolver 2.
# We shouldn't have to per https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html, however if you
# remove this, `getrandom` will fail trying to find `std` when building `mc-sgx-core-types`. This is because
# `mc-sgx-core-types` uses `rand` in it's `dev-dependencies`. `rand` will use the `std` feature of `getrandom`, however
# being in `dev-dependencies` it shouldn't normally get pulled in during a build.
# Even specifying `edition = "2021"` here will not fix this
resolver = "2"

[profile.dev]
opt-level = 0
lto = true
Expand Down
24 changes: 24 additions & 0 deletions core/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@

Utilities for compiling FFI wrappers to SGX libraries.

## Environment Variables

Below are environment variables that affect the building of the SGX FFI
wrappers.

- `SGX_SDK` The path to the Intel SGX SDK. Provides:

1. The location of the SGX SDK headers.

Note: the DCAP headers are assumed to be in the default system include path
2. The location of the SGX SDK libraries for linking

When `SGX_SDK` is not set:

1. The vendored local directory `headers/` will be used for compile time
includes
2. `/opt/intel/sgxsdk` will be used as the linking directory for SGX SDK
libraries

- `CFLAGS` - Used when generating the rust bindings. Useful to specify
system include paths. Multiple arguments can be separated with whitespace.
This does **not** support escaped whitespace as specified in
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html>

[crate-image]: https://img.shields.io/crates/v/mc-sgx-core-build.svg?style=flat-square
[crate-link]: https://crates.io/crates/mc-sgx-core-build
[license-image]: https://img.shields.io/crates/l/mc-sgx-core-build?style=flat-square
Expand Down
63 changes: 63 additions & 0 deletions core/build/headers/tlibc/assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* $OpenBSD: assert.h,v 1.12 2006/01/31 10:53:51 hshoexer Exp $ */
/* $NetBSD: assert.h,v 1.6 1994/10/26 00:55:44 cgd Exp $ */

/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)assert.h 8.2 (Berkeley) 1/21/94
*/

/*
* Unlike other ANSI header files, <assert.h> may usefully be included
* multiple times, with and without NDEBUG defined.
*/

#include <sys/cdefs.h>

#undef assert

#ifdef NDEBUG
# define assert(e) ((void)0)
#else
# define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, __func__, #e))
#endif

#ifndef _ASSERT_H_DECLS
#define _ASSERT_H_DECLS
__BEGIN_DECLS

void _TLIBC_CDECL_ __assert(const char *, int, const char *, const char *);

__END_DECLS
#endif /* Not _ASSERT_H_DECLS */

65 changes: 65 additions & 0 deletions core/build/headers/tlibc/ctype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* $OpenBSD: ctype.h,v 1.22 2010/10/01 20:10:24 guenther Exp $ */
/* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */

/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)ctype.h 5.3 (Berkeley) 4/3/91
*/

#ifndef _CTYPE_H_
#define _CTYPE_H_

#include <sys/cdefs.h>

__BEGIN_DECLS

int _TLIBC_CDECL_ isalnum(int);
int _TLIBC_CDECL_ isalpha(int);
int _TLIBC_CDECL_ iscntrl(int);
int _TLIBC_CDECL_ isdigit(int);
int _TLIBC_CDECL_ isgraph(int);
int _TLIBC_CDECL_ islower(int);
int _TLIBC_CDECL_ isprint(int);
int _TLIBC_CDECL_ ispunct(int);
int _TLIBC_CDECL_ isspace(int);
int _TLIBC_CDECL_ isupper(int);
int _TLIBC_CDECL_ isxdigit(int);
int _TLIBC_CDECL_ tolower(int);
int _TLIBC_CDECL_ toupper(int);
int _TLIBC_CDECL_ isblank(int);
int _TLIBC_CDECL_ isascii(int);

__END_DECLS

#endif /* _CTYPE_H_ */
33 changes: 33 additions & 0 deletions core/build/headers/tlibc/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* $OpenBSD: endian.h,v 1.18 2006/03/27 07:09:24 otto Exp $ */

/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _ENDIAN_H_
#define _ENDIAN_H_

#include <sys/endian.h>

#endif /* _ENDIAN_H_ */

Loading

0 comments on commit d7b4028

Please sign in to comment.