diff --git a/.github/workflows/build-test-publish.yml b/.github/workflows/build-test-publish.yml new file mode 100644 index 000000000..de082796e --- /dev/null +++ b/.github/workflows/build-test-publish.yml @@ -0,0 +1,181 @@ +name: Griddly Build + +on: + push: + branches: ["master", "develop"] + # Run on all pull requests + pull_request: + + +jobs: + build-wasm: + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - name: Checkout + uses: actions/checkout@v2 + + # Install Conan + - name: Install Build Dependencies + run: | + sudo apt-get update + sudo apt-get install python3-pip + pip3 install conan==1.59.0 + + # Build + - name: Build + run: | + conan install deps/wasm/conanfile_wasm.txt -pr:h=deps/wasm/emscripten.profile -pr:b=default -s build_type=Release --build missing -if build_wasm + cmake . -B build_wasm -GNinja -DWASM=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake + cmake --build build_wasm --config Release + + - name: Upload WASM + if: github.ref == 'refs/heads/master' || contains(github.head_ref, 'release-test') + uses: actions/upload-artifact@v3 + with: + name: griddlyjs.wasm + path: Release/bin/griddlyjs.wasm + + - name: Upload JS + if: github.ref == 'refs/heads/master' || contains(github.head_ref, 'release-test') + uses: actions/upload-artifact@v3 + with: + name: griddlyjs.js + path: Release/bin/griddlyjs.js + + build-linux: + runs-on: ubuntu-latest + strategy: + matrix: + manylinux_config: + - python-version: "3.8" + py-bin: cp38-cp38 + platform: manylinux_2_28_x86_64 + - python-version: "3.9" + py-bin: cp39-cp39 + platform: manylinux_2_28_x86_64 + - python-version: "3.10" + py-bin: cp310-cp310 + platform: manylinux_2_28_x86_64 + # - python-version: "3.11" + # py-bin: cp311-cp311 + # platform: manylinux_2_28_x86_64 + - python-version: "3.8" + py-bin: cp38-cp38 + platform: manylinux2014_x86_64 + - python-version: "3.9" + py-bin: cp39-cp39 + platform: manylinux2014_x86_64 + - python-version: "3.10" + py-bin: cp310-cp310 + platform: manylinux2014_x86_64 + container: + image: quay.io/pypa/${{ matrix.manylinux_config.platform }} + env: + PYBIN: ${{ matrix.manylinux_config.py-bin }} + PYVERSION: ${{ matrix.manylinux_config.python-version }} + PLATFORM: ${{ matrix.manylinux_config.platform }} + + steps: + # Checkout the repository + - name: Checkout + uses: actions/checkout@v3 + + # # Set python version + # - name: Set up Python + # uses: actions/setup-python@v3 + # with: + # python-version: ${{ matrix.manylinux_config.python-version }} + + # Install Build Dependencies + - name: Install Build Dependencies + run: | + /opt/python/$PYBIN/bin/pip install poetry cmake conan==1.59.0 + + + # Configure conan for release build + - name: Build + run: | + export CONAN_SYSREQUIRES_SUDO=0 + export PATH=$PATH:/opt/python/$PYBIN/bin + /opt/python/$PYBIN/bin/conan install deps/conanfile.txt -pr:b=default -pr:h=default -pr:h=deps/build.profile -s build_type=Release --build=* -if build_manylinux + /opt/python/$PYBIN/bin/cmake . -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DPython_ROOT_DIR:STRING=/opt/python/$PYBIN -DPYTHON_EXECUTABLE:FILEPATH=/opt/python/$PYBIN/bin/python -S . -B build_manylinux + /opt/python/$PYBIN/bin/cmake --build build_manylinux --config Release + + # Run the tests + - name: Test + run: | + export GTEST_FILTER=-*BlockObserverTest*:*SpriteObserverTest* + /opt/python/$PYBIN/bin/ctest --test-dir build_manylinux + + # Setup python environment + - name: Poetry install + run: | + cd python + /opt/python/$PYBIN/bin/poetry install + + # Run python tests + - name: Python tests + run: | + cd python + /opt/python/$PYBIN/bin/poetry run pytest . + + - name: Python Package + if: github.ref == 'refs/heads/master' || contains(github.head_ref, 'release-test') + run: | + cd python + /opt/python/$PYBIN/bin/poetry build --format=wheel + + # Upload the built wheels + - name: Upload wheel artifacts + if: github.ref == 'refs/heads/master' || contains(github.head_ref, 'release-test') + uses: actions/upload-artifact@v3 + with: + path: python/dist/*.whl + + publish-wheels: + if: github.ref == 'refs/heads/master' || contains(github.head_ref, 'release-test') + needs: build-linux + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - name: Checkout + uses: actions/checkout@v3 + + - name: Download wheel artifacts + uses: actions/download-artifact@v3 + with: + path: python/dist + + - name: Unpack wheels + run: | + ls -lah python/dist/artifact + mv python/dist/artifact/*.whl python/dist/ + + - name: Install Build Dependencies + run: | + sudo apt-get update + sudo apt-get install python3-pip + pip3 install poetry + + - name: Pypi upload (test) + if: contains(github.head_ref, 'release-test') + run: | + cd python + poetry config repositories.test-pypi https://test.pypi.org/legacy/ + poetry config pypi-token.test-pypi ${{ secrets.PYPI_TEST_TOKEN }} + poetry publish -r test-pypi + + - name: Pypi upload (prod) + if: github.ref == 'refs/heads/master' + run: | + poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} + poetry publish + + # build-macos: + # runs-on: macos-latest + + # build-windows: + # runs-on: windows-latest diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 2d56e6e39..000000000 --- a/.gitmodules +++ /dev/null @@ -1,24 +0,0 @@ -[submodule "libs/pybind11"] - path = libs/pybind11 - url = https://github.com/pybind/pybind11.git - ignore = dirty -[submodule "libs/yaml-cpp"] - path = libs/yaml-cpp - url = https://github.com/jbeder/yaml-cpp.git - ignore = dirty -[submodule "libs/glm"] - path = libs/glm - url = https://github.com/g-truc/glm.git - ignore = dirty -[submodule "python/examples/experiments/conditional-action-trees"] - path=python/examples/experiments/conditional-action-trees - url=https://github.com/Bam4d/conditional-action-trees - ignore = dirty -[submodule "python/examples/experiments/rts-self-play"] - path = python/examples/experiments/rts-self-play - url = https://github.com/Bam4d/rts-self-play - ignore = dirty -[submodule "python/examples/experiments/autoregressive-cats"] - path = python/examples/experiments/autoregressive-cats - url = https://github.com/Bam4d/autoregressive-cats - ignore = dirty diff --git a/configure.sh b/configure.sh index 5f8c5017e..ca8dbd0eb 100755 --- a/configure.sh +++ b/configure.sh @@ -29,8 +29,8 @@ echo $PLATFORM if [[ $PLATFORM == "WASM" ]] then - conan install deps/wasm/conanfile_wasm.txt --profile:host deps/wasm/emscripten.profile --profile:build default -s build_type=$BUILD --build missing -if build_wasm + conan install deps/wasm/conanfile_wasm.txt -pr:h=deps/wasm/emscripten.profile -pr:b=default -s build_type=$BUILD --build missing -if build_wasm else - conan install deps/conanfile.txt --profile default --profile deps/build.profile -s build_type=$BUILD --build $CONAN_BUILD -if build + conan install deps/conanfile.txt -pr:b=default -pr:h=default -pr:h=deps/build.profile -s build_type=$BUILD --build $CONAN_BUILD -if build fi diff --git a/azure-pipelines.yml b/old_azure-pipelines.yml similarity index 100% rename from azure-pipelines.yml rename to old_azure-pipelines.yml diff --git a/python/manylinux/build-wheels.sh b/python/manylinux/build-wheels.sh deleted file mode 100755 index 6c61e414e..000000000 --- a/python/manylinux/build-wheels.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -set -ex -set -o pipefail - - -# Download vulkan libs -yum install -y ninja-build - -export CONAN_SYSREQUIRES_SUDO=0 - -# Get Dependencies -/opt/python/$PYBIN/bin/pip install cmake setuptools wheel twine conan==1.59.0 - -export PATH=$PATH:/opt/python/$PYBIN/bin - - -echo "Conan Build Finished" - -# # Cmake Build Griddly -cd /opt/Griddly -conan install deps/conanfile.txt --profile default --profile deps/build.profile -s build_type=Release --build=* -if build_manylinux -/opt/python/$PYBIN/bin/cmake . -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DPython_ROOT_DIR:STRING=/opt/python/$PYBIN -DPYTHON_EXECUTABLE:FILEPATH=/opt/python/$PYBIN/bin/python -S /opt/Griddly -B /opt/Griddly/build_manylinux -/opt/python/$PYBIN/bin/cmake --build /opt/Griddly/build_manylinux --target python_griddly - -# # # Create Wheel -cd python -/opt/python/$PYBIN/bin/python setup.py bdist_wheel --plat $PLAT - diff --git a/python/manylinux/manylinux-build.sh b/python/manylinux/manylinux-build.sh deleted file mode 100755 index 974627021..000000000 --- a/python/manylinux/manylinux-build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -ex - -echo $PYVERSION -echo $PYBIN -echo $GRIDDLY_ROOT -echo $PLAT - -docker run -e PYVERSION=$PYVERSION -e PYBIN=$PYBIN -e PLAT=$PLAT -v "$GRIDDLY_ROOT:/opt/Griddly" quay.io/pypa/$PLAT /opt/Griddly/python/manylinux/build-wheels.sh \ No newline at end of file diff --git a/python/tools/package_resources.py b/python/tools/package_resources.py index f277f00ac..26fdd0d19 100644 --- a/python/tools/package_resources.py +++ b/python/tools/package_resources.py @@ -47,6 +47,7 @@ def build(setup_kwargs): griddly_lib_dir.mkdir(parents=True, exist_ok=True) for lib in libs_to_copy: + print(f" {lib}") shutil.copy(lib, griddly_lib_dir) # Destination for resources diff --git a/src/Griddly/Core/Observers/SpriteObserver.hpp b/src/Griddly/Core/Observers/SpriteObserver.hpp index ec9532a08..e6c8ec5e7 100644 --- a/src/Griddly/Core/Observers/SpriteObserver.hpp +++ b/src/Griddly/Core/Observers/SpriteObserver.hpp @@ -19,14 +19,14 @@ enum class TilingMode { }; struct SpriteDefinition { - std::vector images; + std::vector images{}; TilingMode tilingMode = TilingMode::NONE; glm::vec2 offset = {0, 0}; float scale = 1.0; }; struct SpriteObserverConfig : public VulkanGridObserverConfig { - std::map spriteDefinitions; + std::map spriteDefinitions{}; }; class SpriteObserver : public VulkanGridObserver { diff --git a/tests/src/Griddly/Core/Observers/VectorObserverTest.cpp b/tests/src/Griddly/Core/Observers/VectorObserverTest.cpp index 91a4de81a..43a02f5b5 100644 --- a/tests/src/Griddly/Core/Observers/VectorObserverTest.cpp +++ b/tests/src/Griddly/Core/Observers/VectorObserverTest.cpp @@ -480,7 +480,7 @@ TEST(VectorObserverTest, defaultObserver_global_variables) { 0, 0, false, false}; - + config.globalVariableMapping = {"lightingR", "lightingB"}; uint8_t expectedData[5][5][6] = { diff --git a/tests/src/Griddly/Core/Observers/VulkanObserverTest.cpp b/tests/src/Griddly/Core/Observers/VulkanObserverTest.cpp new file mode 100644 index 000000000..0bb58b5ff --- /dev/null +++ b/tests/src/Griddly/Core/Observers/VulkanObserverTest.cpp @@ -0,0 +1,29 @@ +#define STB_IMAGE_STATIC +#define STB_IMAGE_WRITE_STATIC +#define STB_IMAGE_IMPLEMENTATION +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include +#include +#include + +namespace griddly { + +std::unique_ptr loadExpectedImage(std::string filename) { + int width, height, channels; + + stbi_uc* pixels = stbi_load(filename.c_str(), &width, &height, &channels, STBI_rgb_alpha); + + if (!pixels) { + throw std::runtime_error("Failed to load texture image."); + } + + std::unique_ptr spriteData(pixels); + + return std::move(spriteData); +} + +int write_image(std::string filename, uint8_t* imageData, int stride, int width, int height) { + return stbi_write_png(filename.c_str(), width, height, STBI_rgb_alpha, imageData, stride); +} + +} // namespace griddly \ No newline at end of file diff --git a/tests/src/Griddly/Core/Observers/VulkanObserverTest.hpp b/tests/src/Griddly/Core/Observers/VulkanObserverTest.hpp index d664b6b44..0edd06088 100644 --- a/tests/src/Griddly/Core/Observers/VulkanObserverTest.hpp +++ b/tests/src/Griddly/Core/Observers/VulkanObserverTest.hpp @@ -1,3 +1,4 @@ +#pragma once #define STB_IMAGE_STATIC #define STB_IMAGE_WRITE_STATIC #define STB_IMAGE_IMPLEMENTATION @@ -6,31 +7,14 @@ #include #include -#include - using ::testing::Return; namespace griddly { -inline std::unique_ptr loadExpectedImage(std::string filename) { - int width, height, channels; - - stbi_uc* pixels = stbi_load(filename.c_str(), &width, &height, &channels, STBI_rgb_alpha); - - if (!pixels) { - throw std::runtime_error("Failed to load texture image."); - } - - auto spriteSize = width * height * channels; - - std::unique_ptr spriteData(pixels); +std::unique_ptr loadExpectedImage(std::string filename); - return std::move(spriteData); -} +int write_image(std::string filename, uint8_t* imageData, int stride, int width, int height); -inline int write_image(std::string filename, uint8_t* imageData, int stride, int width, int height) { - return stbi_write_png(filename.c_str(), width, height, STBI_rgb_alpha, imageData, stride); -} MATCHER_P3(ObservationResultMatcher, shape, strides, imageData, "") { for (int x = 0; x < shape[1]; x++) {