SGX.cmake 1.76 KB
Newer Older
nhynes committed
1 2 3 4
if(NOT USE_SGX STREQUAL "OFF")

  set(_sgx_src ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/sgx)
  set(_tvm_u_h ${_sgx_src}/untrusted/tvm_u.h)
5 6
  set(_tvm_t_h ${_sgx_src}/trusted/tvm_t.h)
  set(_tvm_t_c ${_sgx_src}/trusted/tvm_t.c)
nhynes committed
7 8 9 10
  set(_tvm_edl ${_sgx_src}/tvm.edl)
  set(_sgx_ustdc ${RUST_SGX_SDK}/sgx_ustdc)

  set(_urts_lib "sgx_urts")
nhynes committed
11 12
  if(NOT SGX_MODE STREQUAL "HW")
    message(STATUS "Build with SGX support (SIM)")
nhynes committed
13
    set(_urts_lib "${_urts_lib}_sim")
nhynes committed
14 15
  else()
    message(STATUS "Build with SGX support (HW)")
nhynes committed
16 17
  endif()

18
  # build edge routines
nhynes committed
19 20 21
  add_custom_command(
    OUTPUT ${_tvm_u_h}
    COMMAND ${USE_SGX}/bin/x64/sgx_edger8r --untrusted
22 23
      --untrusted --untrusted-dir ${_sgx_src}/untrusted
      --trusted --trusted-dir ${_sgx_src}/trusted
nhynes committed
24 25 26
      --search-path ${USE_SGX}/include --search-path ${RUST_SGX_SDK}/edl
      ${_tvm_edl}
    COMMAND sed -i "4i '#include <tvm/runtime/c_runtime_api.h>'" ${_tvm_u_h}
27
    COMMAND sed -i "4i '#include <tvm/runtime/c_runtime_api.h>'" ${_tvm_t_h}
nhynes committed
28 29 30 31 32 33 34 35 36
    DEPENDS ${_tvm_edl}
  )
  add_custom_command(
    OUTPUT ${_sgx_ustdc}/libsgx_ustdc.a
    COMMAND make
    WORKING_DIRECTORY ${_sgx_ustdc}
  )
  add_custom_target(sgx_edl DEPENDS ${_tvm_u_h} ${_sgx_ustdc}/libsgx_ustdc.a)

37 38 39 40 41 42 43
  # build trusted library
  set_source_files_properties(${_tvm_t_c} PROPERTIES GENERATED TRUE)
  add_library(tvm_t STATIC ${_tvm_t_c})
  add_dependencies(tvm_t sgx_edl)
  target_include_directories(tvm_t PUBLIC ${USE_SGX}/include ${USE_SGX}/include/tlibc)

  # add untrusted runtime files
nhynes committed
44 45 46 47 48 49 50 51
  include_directories(${USE_SGX}/include)
  file(GLOB RUNTIME_SGX_SRCS ${_sgx_src}/untrusted/*.c*)
  list(APPEND TVM_RUNTIME_LINKER_LIBS
    -lpthread
    -L${USE_SGX}/lib64 -l${_urts_lib}
    -L${RUST_SGX_SDK}/sgx_ustdc -lsgx_ustdc)
  list(APPEND RUNTIME_SRCS ${RUNTIME_SGX_SRCS})
endif()