Compare commits

...

5 Commits

7 changed files with 111 additions and 22 deletions

View File

@@ -0,0 +1,82 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false
# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
- os: macos-latest
c_compiler: gcc
- os: macos-latest
c_compiler: cl
steps:
- uses: actions/checkout@v3
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}

View File

@@ -18,7 +18,7 @@ set(SRCS
add_library(mimir ${SRCS} ${PUBLIC_HEADERS})
SET_TARGET_PROPERTIES(
hydra
mimir
PROPERTIES
VERSION 0.1.0
SOVERSION 0.1

View File

@@ -2,7 +2,7 @@
// block.h
// Kraken Engine / Mimir
//
// Copyright 2023 Kearwood Gilbert. All rights reserved.
// Copyright 2024 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
@@ -107,7 +107,7 @@ private:
#if defined(_WIN32) || defined(_WIN64)
HANDLE m_hPackFile;
HANDLE m_hFileMapping;
#elif defined(__APPLE__) || defined(ANDROID)
#elif defined(__unix__) || defined(__APPLE__) || defined(ANDROID)
int m_fdPackFile;
#endif

View File

@@ -2,7 +2,7 @@
// mimir.h
// Kraken Engine / Mimir
//
// Copyright 2023 Kearwood Gilbert. All rights reserved.
// Copyright 2024 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:

View File

@@ -2,7 +2,7 @@
// util.h
// Kraken Engine / Mimir
//
// Copyright 2023 Kearwood Gilbert. All rights reserved.
// Copyright 2024 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:

View File

@@ -2,7 +2,7 @@
// block.cpp
// Kraken Engine
//
// Copyright 2023 Kearwood Gilbert. All rights reserved.
// Copyright 2024 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
@@ -31,12 +31,16 @@
#include "../include/mimir.h"
#include <errno.h>
#if defined(__APPLE__) || defined(ANDROID)
#if defined(__unix__) || defined(__APPLE__) || defined(ANDROID)
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
#include <errno.h>
#include <cassert>
#include <cstring>
#define KRENGINE_MIN_MMAP 32768
#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRENGINE_SYS_ALLOCATION_GRANULARITY - 1))
@@ -60,7 +64,7 @@ void init()
KRENGINE_SYS_ALLOCATION_GRANULARITY = winSysInfo.dwAllocationGranularity;
KRENGINE_SYS_PAGE_SIZE = winSysInfo.dwPageSize;
#elif defined(__APPLE__) || defined(ANDROID)
#elif defined(__APPLE__) || __linux__ || defined(ANDROID)
KRENGINE_SYS_PAGE_SIZE = getpagesize();
KRENGINE_SYS_ALLOCATION_GRANULARITY = KRENGINE_SYS_PAGE_SIZE;
@@ -78,7 +82,7 @@ Block::Block()
#if defined(_WIN32) || defined(_WIN64)
m_hPackFile = INVALID_HANDLE_VALUE;
m_hFileMapping = NULL;
#elif defined(__APPLE__)
#elif __linux__ || defined(__APPLE__)
m_fdPackFile = 0;
#endif
m_fileName = "";
@@ -187,7 +191,7 @@ bool Block::load(const std::string& path)
m_fdPackFile = open(path.c_str(), O_RDONLY);
if (m_fdPackFile >= 0) {
m_fileOwnerDataBlock = this;
m_fileName = KRResource::GetFileBase(path);
m_fileName = util::GetFileBase(path);
struct stat statbuf;
if (fstat(m_fdPackFile, &statbuf) >= 0) {
m_data_size = statbuf.st_size;
@@ -212,7 +216,7 @@ Block* Block::getSubBlock(int start, int length)
#if defined(_WIN32) || defined(_WIN64)
if (m_hPackFile != INVALID_HANDLE_VALUE) {
new_block->m_hPackFile = m_hPackFile;
#elif defined(__APPLE__) || defined(ANDROID)
#elif __linux__ || defined(__APPLE__) || defined(ANDROID)
if (m_fdPackFile) {
new_block->m_fdPackFile = m_fdPackFile;
#else
@@ -253,7 +257,7 @@ void Block::expand(size_t size)
{
#if defined(_WIN32) || defined(_WIN64)
if (m_data == NULL && m_hPackFile == INVALID_HANDLE_VALUE) {
#elif defined(__APPLE__) || defined(ANDROID)
#elif __linux__ || defined(__APPLE__) || defined(ANDROID)
if (m_data == NULL && m_fdPackFile == 0) {
#else
#error Unsupported
@@ -328,7 +332,7 @@ void Block::copy(void* dest, int start, int count)
bytes_remaining -= bytes_read;
}
assert(bytes_remaining == 0);
#elif defined(__APPLE__) || defined(ANDROID)
#elif __linux__ || defined(__APPLE__) || defined(ANDROID)
if (m_lockCount == 0 && m_fdPackFile != 0) {
// Optimization: If we haven't mmap'ed or malloced the data already, pread() it directly from the file into the buffer
ssize_t r = pread(m_fdPackFile, dest, count, start + m_data_offset);
@@ -418,7 +422,7 @@ bool Block::save(const std::string & path)
return success;
#elif defined(__APPLE__) || defined(ANDROID)
#elif __linux__ || defined(__APPLE__) || defined(ANDROID)
int fdNewFile = open(path.c_str(), O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
if (fdNewFile == -1) {
return false;
@@ -430,7 +434,7 @@ bool Block::save(const std::string & path)
// Now map it...
void* pNewData = mmap(0, m_data_size, PROT_READ | PROT_WRITE, MAP_SHARED, fdNewFile, 0);
if (pNewData == (caddr_t)-1) {
if (pNewData == (void*)-1) {
close(fdNewFile);
return false;
}
@@ -501,7 +505,7 @@ void Block::lock()
// Memory mapped file; ensure data is mapped to ram
#if defined(_WIN32) || defined(_WIN64)
if (m_hPackFile != INVALID_HANDLE_VALUE) {
#elif defined(__APPLE__) || defined(ANDROID)
#elif __linux__ || defined(__APPLE__) || defined(ANDROID)
if (m_fdPackFile) {
#else
#error Unsupported
@@ -525,11 +529,13 @@ void Block::lock()
ReportWindowsLastError("MapViewOfFileFromApp");
}
assert(m_mmapData != NULL);
#elif defined(__APPLE__) || defined(ANDROID)
#elif __linux__ || defined(__APPLE__) || defined(ANDROID)
//fprintf(stderr, "Block::lock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount);
// Round m_data_offset down to the next memory page, as required by mmap
if ((m_mmapData = mmap(0, m_data_size + alignment_offset, m_bReadOnly ? PROT_READ : PROT_WRITE, MAP_SHARED, m_fdPackFile, m_data_offset - alignment_offset)) == (caddr_t)-1) {
if ((m_mmapData = mmap(0, m_data_size + alignment_offset, m_bReadOnly ? PROT_READ : PROT_WRITE, MAP_SHARED, m_fdPackFile, m_data_offset - alignment_offset)) == (void*)-1) {
/*
// Disabled until logging utility can be implemented
int iError = errno;
switch (iError) {
case EACCES:
@@ -557,6 +563,7 @@ void Block::lock()
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "mmap failed with errno: %i", iError);
break;
}
*/
assert(false); // mmap() failed.
}
#else
@@ -585,7 +592,7 @@ void Block::unlock()
// Memory mapped file; ensure data is unmapped from ram
#if defined(_WIN32) || defined(_WIN64)
if (m_hPackFile != INVALID_HANDLE_VALUE) {
#elif defined(__APPLE__) || defined(ANDROID)
#elif __linux__ || defined(__APPLE__) || defined(ANDROID)
if (m_fdPackFile) {
#else
#error Undefined
@@ -603,7 +610,7 @@ void Block::unlock()
CloseHandle(m_hFileMapping);
m_hFileMapping = NULL;
}
#elif defined(__APPLE__) || defined(ANDROID)
#elif __linux__ || defined(__APPLE__) || defined(ANDROID)
munmap(m_mmapData, m_data_size);
#else
#error Undefined

View File

@@ -2,7 +2,7 @@
// util.cpp
// Kraken Engine / Mimir
//
// Copyright 2023 Kearwood Gilbert. All rights reserved.
// Copyright 2024 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met: