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 android build #45

Merged
merged 16 commits into from
Feb 28, 2022
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
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ CommentPragmas: '.* \\(param|tparam|brief|detail|details|return|returns|note|wa
# EmptyLineBeforeAccessModifier: LogicalBlock
# IndentRequires: true
# BreakBeforeConceptDeclarations: true
IndentPPDirectives: BeforeHash
...
29 changes: 26 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ jobs:
container:
image: gcc:11.2.0
strategy:
fail-fast: false
matrix:
graphics: [vulkan, all]
fail-fast: false
matrix:
graphics: [vulkan, all]
name: ubuntu-benchmark
needs: ubuntu
runs-on: ubuntu-latest
Expand All @@ -126,3 +126,26 @@ jobs:
name: ubuntu-${{ matrix.graphics }}
path: results.json
if-no-files-found: error
android:
env:
CC: gcc
CXX: g++
strategy:
fail-fast: false
matrix:
graphics: [vulkan]
name: android
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v1
with:
submodules: recursive
- name: dependencies
run: yes | $ANDROID_SDK_ROOT/tools/bin/sdkmanager --licenses
- name: initialize
run: cmake --preset=android-release-${{ matrix.graphics }}
- name: compile
run: cmake --build --preset=android-release-${{ matrix.graphics }}
- name: verify
run: python3 -c "import os;import sys;sys.exit(0) if os.path.exists('builds/android/main/build/outputs/bundle/release/main-release.aab') else sys.exit(1)"
95 changes: 69 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ endif()
###############################################################################
### general options and setup ###
###############################################################################
OPTION(PE_SOURCE_ONLY "set to off to not compile the sub-projects" OFF)
OPTION(PE_PROFILER "enables the internal profiler" OFF)
OPTION(PE_ANALYZE "enables static analyzers for the given platform" OFF)
OPTION(PE_VERBOSE "verbose error checking in the default compile options" OFF)
Expand Down Expand Up @@ -50,15 +49,12 @@ OPTION(PE_BENCHMARKS "Enable the generation of benchmarks" OFF)
set(PE_BUILD_DIR "${CMAKE_BINARY_DIR}/builds/" CACHE PATH "target location where to build the project to")
set(PE_DEFINES -DUNICODE;-D_UNICODE;-DNOMINMAX CACHE INTERNAL "")
OPTION(PE_DEFAULT_COMPILE_OPTIONS "Use the default set of compile options (check 'compile options' section in the CMakelists.txt file)" TRUE)

set(ANDROID_SDK "" CACHE PATH "override root android sdk location")
set(ANDROID_BUNDLETOOL "" CACHE PATH "override android bundletool location")
set(ANDROID_GRADLE "" CACHE PATH "override gradle location")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if(PE_GLES)
message("enabling GLES")
list(APPEND PE_DEFINES -DPE_GLES)
endif()

if(PE_PLATFORM STREQUAL AUTO)
if(PE_PLATFORM STREQUAL "AUTO")
if(WIN32)
set(PE_PLATFORM WINDOWS)
elseif(UNIX)
Expand All @@ -68,13 +64,54 @@ if(PE_PLATFORM STREQUAL AUTO)
endif()
endif()

if(PE_PLATFORM STREQUAL "ANDROID" AND NOT EXISTS "${CMAKE_SOURCE_DIR}/AndroidManifest.xml")
SET(Python_ADDITIONAL_VERSIONS 3 3.0)
find_package(PythonInterp REQUIRED)
set(ANDROID_PY_ARGS)
if(NOT ANDROID_SDK STREQUAL "")
list(APPEND --sdk "${ANDROID_SDK}" ANDROID_PY_ARGS)
endif()
if(NOT ANDROID_GRADLE STREQUAL "")
list(APPEND --gradle "${ANDROID_GRADLE}" ANDROID_PY_ARGS)
endif()
if(NOT ANDROID_BUNDLETOOL STREQUAL "")
list(APPEND --bundletool "${ANDROID_BUNDLETOOL}" ANDROID_PY_ARGS)
endif()

string(TOLOWER ${CMAKE_BUILD_TYPE} build_type)
add_custom_target(paradigm_android_generate ALL)
add_custom_command(TARGET paradigm_android_generate
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/android.py
--output ${PE_BUILD_DIR}/android
${ANDROID_PY_ARGS}
USES_TERMINAL BYPRODUCTS ${PE_BUILD_DIR}/android/gradle.properties)

add_custom_target(paradigm_android_build ALL DEPENDS paradigm_android_generate)
add_custom_command(TARGET paradigm_android_build
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/android.py
--output ${PE_BUILD_DIR}/android
--build gles ${PE_GLES} vulkan ${PE_VULKAN} vulkan.version ${VK_VERSION}
--type ${build_type}
${ANDROID_PY_ARGS}
USES_TERMINAL)
return()
endif()

if(PE_GLES)
message("enabling GLES")
list(APPEND PE_DEFINES -DPE_GLES)
endif()

string(TOUPPER PE_MODE PE_MODE)
list(APPEND PE_DEFINES -DPLATFORM_${PE_MODE})

# experimental early support for not supporting vulkan
if(PE_VULKAN)
message("enabling VULKAN")
list(APPEND PE_DEFINES -DPE_VULKAN)
if(NOT DEFINED VK_VERSION OR VK_VERSION STREQUAL "")
message(FATAL_ERROR ${VK_VERSION})
message(FATAL_ERROR "requested 'vulkan' backend, but did not set 'VK_VERSION'")
endif()
endif()

if(PE_MOLTEN)
Expand All @@ -96,7 +133,7 @@ if(PE_PROFILER)
endif()


if(NOT VK_STATIC AND NOT PE_SOURCE_ONLY)
if(NOT VK_STATIC)
list(APPEND PE_DEFINES -DVK_NO_PROTOTYPES)
elseif(VK_STATIC)
list(APPEND PE_DEFINES -DVK_STATIC)
Expand All @@ -108,6 +145,10 @@ else()
list(APPEND PE_DEFINES -DPE_RELEASE)
endif()

if(${PE_PLATFORM} STREQUAL ANDROID AND (NOT DEFINED ANDROID_NDK OR ANDROID_NDK STREQUAL ""))
message(FATAL_ERROR "Trying to build 'android' target outside of the gradle context is not supported.")
endif()

###############################################################################
### validation ###
###############################################################################
Expand Down Expand Up @@ -252,6 +293,11 @@ endif()

set(HAS_WSI FALSE)
set(PE_SURFACE "unknown")
if(PE_PLATFORM STREQUAL "ANDROID")
set(HAS_WSI TRUE)
set(PE_SURFACE "ANDROID")
list(APPEND PE_DEFINES -DSURFACE_ANDROID;-DVK_USE_PLATFORM_ANDROID_KHR)
endif()
if(NOT HAS_WSI AND PE_WSI_D2D)
list(APPEND PE_DEFINES -DSURFACE_D2D)
message("using D2D WSI")
Expand Down Expand Up @@ -283,22 +329,19 @@ string(TOLOWER ${PE_SURFACE} PE_SURFACE_LOWERCASE)

add_definitions(${PE_DEFINES})

if(NOT PE_SOURCE_ONLY)
add_subdirectory(extern)
add_subdirectory(extern)

add_subdirectory(psl)
add_subdirectory(core)
if(PE_TESTS)
add_subdirectory(tests)
endif()

if(PE_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
add_subdirectory(psl)
add_subdirectory(core)
if(PE_TESTS)
add_subdirectory(tests)
endif()

if(EXISTS "${PROJECT_SOURCE_DIR}/modules.txt")
include(${PROJECT_SOURCE_DIR}/modules.txt)
endif()
else()
message("did not compile the project by request")
if(PE_BENCHMARKS)
add_subdirectory(benchmarks)
endif()


if(EXISTS "${PROJECT_SOURCE_DIR}/modules.txt")
include(${PROJECT_SOURCE_DIR}/modules.txt)
endif()
38 changes: 37 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,32 @@
"cacheVariables": {
"PE_MODE": "release"
}
},
{
"name": "android-release-vulkan",
"displayName": "Android Vulkan (Release)",
"inherits": [
"settings-vulkan",
"settings-project"
],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"PE_MODE": "release",
"PE_PLATFORM": "ANDROID"
}
},
{
"name": "android-debug-vulkan",
"displayName": "Android Vulkan (Debug)",
"inherits": [
"settings-vulkan",
"settings-project"
],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"PE_MODE": "debug",
"PE_PLATFORM": "ANDROID"
}
}
],
"buildPresets": [
Expand Down Expand Up @@ -248,6 +274,16 @@
"name": "gnu-linux-release-vulkan",
"displayName": "Release",
"configurePreset": "gnu-linux-release-vulkan"
},
{
"name": "android-release-vulkan",
"displayName": "Release",
"configurePreset": "android-release-vulkan"
},
{
"name": "android-debug-vulkan",
"displayName": "Debug",
"configurePreset": "android-debug-vulkan"
}
]
}
}
2 changes: 1 addition & 1 deletion benchmarks/src/ecs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ auto get_random_entities(const psl::array<entity>& source, size_t count, std::mt
template <typename... Ts>
void run_system(benchmark::State& gState, state_t& state, const std::vector<entity>& count)
{
assert(count.size() == 5);
psl_assert(count.size() == 5, "expected size to be 5");
auto entities = state.create(count[0]);
std::random_device rd;
std::mt19937 g(rd());
Expand Down
15 changes: 8 additions & 7 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
SET(Python_ADDITIONAL_VERSIONS 3 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
find_package(PythonInterp REQUIRED)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${GEN})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${GEN})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc/fwd" PREFIX "fwd" FILES ${FWD})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC_GLES})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC_GLES})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC_VULKAN})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC_VULKAN})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC_GLES})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC_GLES})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC_VULKAN})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC_VULKAN})

if(VS_USE_NATVIS)
file(GLOB_RECURSE NATVIS nvs/*.natvis)
Expand Down Expand Up @@ -126,6 +126,7 @@ target_include_directories(${LOCAL_PROJECT}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/inc
${vulkan_SOURCE_DIR}/include
$<IF:$<STREQUAL:"${PE_PLATFORM}","ANDROID">,${ANDROID_NDK}/sources/android/native_app_glue,>
PRIVATE
${WSI_INC}
)
Expand Down
2 changes: 1 addition & 1 deletion core/inc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ meta/shader
meta/texture

os/surface
os/context

systems/input

Expand Down Expand Up @@ -76,7 +77,6 @@ ecs/components/text
utility/geometry
)


list(TRANSFORM INC PREPEND inc/)
list(TRANSFORM INC APPEND .hpp)

Expand Down
2 changes: 1 addition & 1 deletion core/inc/data/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace core
}
break;
}
assert(false && "unknown sized stream");
psl_assert(false, "unknown sized stream");
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion core/inc/gfx/render_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace psl
}
}

assert(it->first->references == 0);
psl_assert(it->first->references == 0, "Should have 0 references");

for(auto* node : it->second)
{
Expand Down
2 changes: 2 additions & 0 deletions core/inc/gfx/swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace core::os
{
class surface;
class context;
}

namespace core::gfx
Expand All @@ -27,6 +28,7 @@ namespace core::gfx
psl::meta::file* metaFile,
core::resource::handle<core::os::surface> surface,
core::resource::handle<core::gfx::context> context,
core::os::context& os_context,
bool use_depth = true);

~swapchain() {};
Expand Down
1 change: 1 addition & 0 deletions core/inc/gfx/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "psl/ustring.hpp"
#include <optional>
#include <variant>
#include <vector>

namespace core::gfx
{
Expand Down
Loading