SGX.cmake 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

nhynes committed
18 19 20 21
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)
22 23
  set(_tvm_t_h ${_sgx_src}/trusted/tvm_t.h)
  set(_tvm_t_c ${_sgx_src}/trusted/tvm_t.c)
nhynes committed
24 25 26 27
  set(_tvm_edl ${_sgx_src}/tvm.edl)
  set(_sgx_ustdc ${RUST_SGX_SDK}/sgx_ustdc)

  set(_urts_lib "sgx_urts")
nhynes committed
28 29
  if(NOT SGX_MODE STREQUAL "HW")
    message(STATUS "Build with SGX support (SIM)")
nhynes committed
30
    set(_urts_lib "${_urts_lib}_sim")
nhynes committed
31 32
  else()
    message(STATUS "Build with SGX support (HW)")
nhynes committed
33 34
  endif()

35
  # build edge routines
nhynes committed
36 37 38
  add_custom_command(
    OUTPUT ${_tvm_u_h}
    COMMAND ${USE_SGX}/bin/x64/sgx_edger8r --untrusted
39 40
      --untrusted --untrusted-dir ${_sgx_src}/untrusted
      --trusted --trusted-dir ${_sgx_src}/trusted
nhynes committed
41 42 43
      --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}
44
    COMMAND sed -i "4i '#include <tvm/runtime/c_runtime_api.h>'" ${_tvm_t_h}
nhynes committed
45 46 47 48 49 50 51 52 53
    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)

54 55 56 57 58 59 60
  # 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
61 62 63 64 65 66 67
  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})
68 69

  include_directories(${RUST_SGX_SDK}/edl ${RUST_SGX_SDK}/common)
nhynes committed
70
endif()