Skip to content

Commit

Permalink
New VMM extension integration mechanism
Browse files Browse the repository at this point in the history
1) New vmm_extension() macro for registering bareflank extensions to the
build system from build configuration file

2) New VMM extension-specific config variables and extension-specific macros

3) Added vmm_ex.cmake to be included by all Bareflank extensions

4) Updated build system documentation

[RFC] #545

Signed-off-by: JaredWright <jared.wright12@gmail.com>
  • Loading branch information
JaredWright committed Dec 13, 2017
1 parent 23d8295 commit 98282e8
Show file tree
Hide file tree
Showing 12 changed files with 1,000 additions and 95 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ project(hypervisor)
# Cmake global properties
# ------------------------------------------------------------------------------

include(ExternalProject)
include(${CMAKE_SOURCE_DIR}/scripts/cmake/global_vars.cmake)
include(${CMAKE_SOURCE_DIR}/scripts/cmake/macros.cmake)
include(${BF_CONFIG_DIR}/default.cmake)
include(${BF_FLAGS_DIR}/flags.cmake)
include(${BF_SCRIPTS_DIR}/cmake/build_rules.cmake)
include(${BF_SCRIPTS_DIR}/cmake/targets.cmake)
include(ExternalProject)

validate_build()

Expand Down Expand Up @@ -224,5 +224,7 @@ if(ENABLE_UNITTESTING)
endif()
endif()


add_vmm_extensions()
print_banner()
print_usage()
27 changes: 8 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ supported platforms and their dependencies:

#### Arch Linux:
```
sudo pacman -S git linux-headers nasm clang cmake
sudo pacman -S git linux-headers nasm clang cmake base-devel
```

#### Ubuntu 17.04 (or Higher):
Expand Down Expand Up @@ -177,30 +177,19 @@ bcdedit.exe /set testsigning ON
```
## Compilation Instructions

To compile, run the following commands:
To compile with default settings for your host environment, run the following commands:

```
git clone -b dev https://github.com/bareflank/hypervisor.git
mkdir hypervisor/build; cd hypervisor/build
cmake ..
mkdir build; cd build
cmake ../hypervisor
make -j<# cores + 1>
```

Also, if your modifying the hypervisor, we highly recommend enabling
unit testing and developer mode. This will enable the various different tools
that are needed to pass all of our CI tests. This also compiles the hypervisor
in debug mode.
- `-DENABLE_UNITTESTING=ON`
- `-DENABLE_DEVELOPER_MODE=ON`

Once this is enabled, you can run the following commands before submitting a
PR:
- `make test`
- `make format`
- `make tidy`

If you wish to enable the extended APIs, you can do so using the following.
- `-DENABLE_EXTENDED_APIS=ON` and/or `-DEXTENDED_APIS_PATH=<path>`
For more detailed build instuctions and configurations, see the
[detailed build instructions](scripts/docs/build_instructions.md).
For instructions on building and creating Bareflank extensions, see the
[extension build instructions](scripts/docs/extension_instructions.md)

## Usage Instructions

Expand Down
5 changes: 5 additions & 0 deletions scripts/cmake/build_rules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ add_build_rule(
FAIL_MSG "Extended APIs unit tests require VMM unit tests, please enable UNITTEST_VMM"
)

add_build_rule(
FAIL_ON ${UNITTEST_VMM_EXTENSIONS} AND NOT ${UNITTEST_VMM}
FAIL_MSG "VMM extension unit tests require VMM unit tests, please enable UNITTEST_VMM"
)

# ------------------------------------------------------------------------------
# Developer-mode build rules
# ------------------------------------------------------------------------------
Expand Down
41 changes: 41 additions & 0 deletions scripts/cmake/config/bfconfig_template.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Bareflank Hypervisor
# Copyright (C) 2015 Assured Information Security, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# ------------------------------------------------------------------------------
# Bareflank Build Configurations
# ------------------------------------------------------------------------------

# set(BUILD_TYPE Debug)
# set(BUILD_VMM_STATIC ON)
# set(ENABLE_DEVELOPER_MODE ON)

# ------------------------------------------------------------------------------
# Bareflank Extensions
# ------------------------------------------------------------------------------

# vmm_extension(
# extended_apis
# GIT_REPOSITORY https://github.com/bareflank/extended_apis.git
# GIT_TAG dev
# )

# vmm_extension(
# extended_apis
# SOURCE_DIR ~/bareflank/my_extension
# DEPENDS extended_apis
# )
52 changes: 43 additions & 9 deletions scripts/cmake/config/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,36 @@
# using: cmake /path/to/src -DBFCONFIG=/path/to/config.cmake

# ------------------------------------------------------------------------------
# Import user configuration file (if specified)
# Import Bareflank build configuration file
# ------------------------------------------------------------------------------

# -DBFCONFIG=/path/to/bfconfig.cmake takes first precedence
# Search relative to the build directory first, then the source tree defaults
if(BFCONFIG)
find_file(_BFCONFIG_PATH ${BFCONFIG} ${BF_CONFIG_DIR})
set(_BFCONFIG_PATH ${_BFCONFIG_PATH} CACHE INTERNAL "")
if(EXISTS ${_BFCONFIG_PATH})
message(STATUS "Configuring Bareflank using: ${_BFCONFIG_PATH}")
include(${_BFCONFIG_PATH})
# Prevent infinite loop this file is specified
if(${BFCONFIG} STREQUAL default.cmake)
message(STATUS "Building Bareflank with default settings")
else()
message(FATAL_ERROR "Configuration file ${BFCONFIG} not found")
find_file(_BFCONFIG_PATH ${BFCONFIG} PATHS ${BF_BUILD_DIR} ${BF_CONFIG_DIR})
if(EXISTS ${_BFCONFIG_PATH})
message(STATUS "Configuring Bareflank using: ${_BFCONFIG_PATH}")
include(${_BFCONFIG_PATH})
else()
message(FATAL_ERROR "Configuration file ${BFCONFIG} not found")
endif()
endif()
# Next, search the current build directory for "bfconfig.cmake"
elseif(EXISTS ${BF_BUILD_DIR}/bfconfig.cmake)
message(STATUS "Configuring Bareflank using: ${BF_BUILD_DIR}/bfconfig.cmake")
include(${BF_BUILD_DIR}/bfconfig.cmake)
# Otherwise, fall back to the empty bfconfig template file
else()
message(STATUS "No configuration specified, using default settings")
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${BF_CONFIG_DIR}/bfconfig_template.cmake
${BF_BUILD_DIR}/bfconfig.cmake
)
message(STATUS "No build configuration specified, using default settings")
endif()

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -140,6 +156,13 @@ add_config(
DESCRIPTION "Path to the Bareflank Extended APIs"
)

add_config(
CONFIG_NAME BUILD_VMM_EXTENSIONS
CONFIG_TYPE BOOL
DEFAULT_VAL ON
DESCRIPTION "Build all configured Bareflank VMM extensions"
)

if(${CMAKE_VERBOSE_MAKEFILE})
set(_BUILD_VERBOSE ON CACHE INTERNAL "")
else()
Expand Down Expand Up @@ -254,7 +277,18 @@ add_config(
CONFIG_NAME UNITTEST_VMM
CONFIG_TYPE BOOL
DEFAULT_VAL ${ENABLE_UNITTESTING}
DESCRIPTION "Build unit tests for the VMM"
DESCRIPTION "Build VMM unit tests"
)

set(_DEFAULT_UNITTEST_VMM_EXTENSIONS OFF CACHE INTERNAL "")
if(${ENABLE_UNITTESTING} AND ${BUILD_VMM_EXTENSIONS} AND ${UNITTEST_VMM})
set(_DEFAULT_UNITTEST_VMM_EXTENSIONS ON)
endif()
add_config(
CONFIG_NAME UNITTEST_VMM_EXTENSIONS
CONFIG_TYPE BOOL
DEFAULT_VAL ${_DEFAULT_UNITTEST_VMM_EXTENSIONS}
DESCRIPTION "Build VMM extension unit tests"
)

set(_DEFAULT_UNITTEST_BFDRIVER OFF CACHE INTERNAL "")
Expand Down
129 changes: 129 additions & 0 deletions scripts/cmake/config/default_ex.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#
# Bareflank Hypervisor
# Copyright (C) 2015 Assured Information Security, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# ------------------------------------------------------------------------------
# README
# ------------------------------------------------------------------------------

# This file defines all configurable cmake variables available to Barefank
# VMM extensions, set to their default value. These configuration are NOT
# available to base Bareflank hypervisor projects. VMM extension projects
# can use both these configurations PLUS the base hypervisor configurations.

# Each configuration here indicates the Bareflank suggested convention as
# a default value. The goal is to encourage a "convention over configuration"
# mindset for extension developers. If extension developers choose not follow
# a suggested convention, they can override a configuration using two methods:
#
# 1) Specify each configuration as CMAKE_ARGS to the vmm_extension() macro. Ex:
#
# vmm_extension(
# extension_name
# CMAKE_ARGS -DVMM_EX_BUILD_RULES=/path/to/build_rules.cmake
# )
#
# 2) Override a configuration in the extension's CMakeLists.txt file BEFORE
# calling include(${VMM_EXTENSION}). Ex:
#
# set(VMM_EX_BUILD_RULES "/path/to/build_rules.cmake")
# set(VMM_EX_UNITTEST_PATH "/path/to/the/unit/tests")
# include(${VMM_EXTENSION})
#

# ------------------------------------------------------------------------------
# Source tree structure
# ------------------------------------------------------------------------------

add_config(
CONFIG_NAME VMM_EX_TOP_DIR
CONFIG_TYPE PATH
DEFAULT_VAL ${CMAKE_CURRENT_SOURCE_DIR}
DESCRIPTION "Path to the top directory for this VMM extension"
)

add_config(
CONFIG_NAME VMM_EX_SOURCE_DIR
CONFIG_TYPE PATH
DEFAULT_VAL ${VMM_EX_TOP_DIR}/src
DESCRIPTION "Path to the source code directory for this VMM extension"
SKIP_VALIDATION
)

add_config(
CONFIG_NAME VMM_EX_INCLUDE_DIR
CONFIG_TYPE PATH
DEFAULT_VAL ${VMM_EX_TOP_DIR}/include
DESCRIPTION "Path to the header include directory for this VMM extension"
SKIP_VALIDATION
)

add_config(
CONFIG_NAME VMM_EX_UNITTEST_DIR
CONFIG_TYPE PATH
DEFAULT_VAL ${VMM_EX_TOP_DIR}/test
DESCRIPTION "Path to the unit test directory for this VMM extension"
SKIP_VALIDATION
)

# ------------------------------------------------------------------------------
# Build system features
# ------------------------------------------------------------------------------

add_config(
CONFIG_NAME VMM_EX_CONFIGS
CONFIG_TYPE FILE
DEFAULT_VAL ${VMM_EX_TOP_DIR}/configs.cmake
DESCRIPTION "Path to extention-specific build configurations to be added "
"for this VMM extension"
SKIP_VALIDATION
)

add_config(
CONFIG_NAME VMM_EX_BUILD_RULES
CONFIG_TYPE FILE
DEFAULT_VAL ${VMM_EX_TOP_DIR}/build_rules.cmake
DESCRIPTION "Path to a build rules file to be validated before building "
"this VMM extension"
SKIP_VALIDATION
)

# ------------------------------------------------------------------------------
# Read-only variables
# ------------------------------------------------------------------------------

add_config(
CONFIG_NAME VMM_EX_IS_UNITTEST_BUILD
CONFIG_TYPE INTERNAL
DEFAULT_VAL OFF
DESCRIPTION "The build system sets this variable to ON if this extension's "
"unit tests are currently being built, rather than it's source"
SKIP_VALIDATION
)

if(VMM_EX_IS_UNTTEST_BUILD)
set(_VMM_EX_SYSROOT_DEFAULT ${BUILD_SYSROOT_TEST})
else()
set(_VMM_EX_SYSROOT_DEFAULT ${BUILD_SYSROOT_VMM})
endif()
add_config(
CONFIG_NAME VMM_EX_SYSROOT
CONFIG_TYPE INTERNAL
DEFAULT_VAL ${_VMM_EX_SYSROOT_DEFAULT}
DESCRIPTION "Path to this VMM extension's sysroot"
SKIP_VALIDATION
)

0 comments on commit 98282e8

Please sign in to comment.