From f95a352f542b1480dfd51eafe625c6a613941144 Mon Sep 17 00:00:00 2001 From: "Vu D. Truong (InNoobWeTrust)" Date: Tue, 14 Jan 2025 02:07:15 +0700 Subject: [PATCH 1/2] devx: add devcontainer Allow contributors to contribute with less hassle --- .devcontainer/Dockerfile | 18 ++++++++++ .devcontainer/devcontainer.json | 30 ++++++++++++++++ .devcontainer/reinstall-cmake.sh | 59 ++++++++++++++++++++++++++++++++ README.md | 41 ++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/reinstall-cmake.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..01a5554b0 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04 + +ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none" + +# Optionally install the cmake for vcpkg +COPY ./reinstall-cmake.sh /tmp/ + +RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ + chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ + fi \ + && rm -f /tmp/reinstall-cmake.sh + +# [Optional] Uncomment this section to install additional vcpkg ports. +# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..6486dab9c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,30 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/cpp +{ + "name": "C++", + "build": { + "dockerfile": "Dockerfile" + }, + "features": { + "ghcr.io/stuartleeks/dev-container-features/shell-history:0": {}, + "ghcr.io/sebst/devcontainer-features/pkgx:1": {} + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "git submodule update --init", + + // Use 'postAttachCommand' to run commands after the container is attached. + "postAttachCommand": "pkgx install npx && npx -y runme run --filename README.md -t devcontainer -y" + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/reinstall-cmake.sh b/.devcontainer/reinstall-cmake.sh new file mode 100644 index 000000000..408b81d22 --- /dev/null +++ b/.devcontainer/reinstall-cmake.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +set -e + +CMAKE_VERSION=${1:-"none"} + +if [ "${CMAKE_VERSION}" = "none" ]; then + echo "No CMake version specified, skipping CMake reinstallation" + exit 0 +fi + +# Cleanup temporary directory and associated files when exiting the script. +cleanup() { + EXIT_CODE=$? + set +e + if [[ -n "${TMP_DIR}" ]]; then + echo "Executing cleanup of tmp files" + rm -Rf "${TMP_DIR}" + fi + exit $EXIT_CODE +} +trap cleanup EXIT + + +echo "Installing CMake..." +apt-get -y purge --auto-remove cmake +mkdir -p /opt/cmake + +architecture=$(dpkg --print-architecture) +case "${architecture}" in + arm64) + ARCH=aarch64 ;; + amd64) + ARCH=x86_64 ;; + *) + echo "Unsupported architecture ${architecture}." + exit 1 + ;; +esac + +CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" +CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" +TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) + +echo "${TMP_DIR}" +cd "${TMP_DIR}" + +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O + +sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" +sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license + +ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake +ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest diff --git a/README.md b/README.md index 8ab39aba8..045089666 100644 --- a/README.md +++ b/README.md @@ -394,6 +394,47 @@ make -j4 cortex -h ``` +#### Devcontainer / Codespaces + +1. Open Cortex.cpp repository in Codespaces or local devcontainer + + [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/janhq/cortex.cpp?quickstart=1) + + ```sh + devcontainer up --workspace-folder . + ``` + +2. Configure vpkg in `engine/vcpkg`: + +```bash {"tag": "devcontainer"} +cd engine/vcpkg +export VCPKG_FORCE_SYSTEM_BINARIES="$([[ $(uname -m) == 'arm64' ]] && echo '1' || echo '0')" +./bootstrap-vcpkg.sh +``` + +3. Build the Cortex.cpp inside the `engine/build` folder: + +```bash {"tag": "devcontainer"} +cd engine +mkdir -p build +cd build +cmake .. -DCMAKE_TOOLCHAIN_FILE=$(realpath ..)/vcpkg/scripts/buildsystems/vcpkg.cmake +make -j$(grep -c ^processor /proc/cpuinfo) +``` + +4. Verify that Cortex.cpp is installed correctly by getting help information. + +```sh {"tag": "devcontainer"} +cd engine/build +./cortex -h +``` + +5. Everytime a rebuild is needed, just run the commands above using oneliner + +```sh +npx -y runme run --filename README.md -t devcontainer -y +``` + ## Uninstallation ### Windows From 606628644409192aed46080a9017346963c7857f Mon Sep 17 00:00:00 2001 From: "Vu D. Truong (InNoobWeTrust)" Date: Tue, 14 Jan 2025 03:10:59 +0700 Subject: [PATCH 2/2] devx: increase minimum machine requirement for devcontainer --- .devcontainer/devcontainer.json | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6486dab9c..8af8ffd59 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,30 +1,35 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/cpp { + "hostRequirements": { + "cpus": 4, + "memory": "8gb", + "storage": "32gb" + }, "name": "C++", "build": { "dockerfile": "Dockerfile" }, "features": { "ghcr.io/stuartleeks/dev-container-features/shell-history:0": {}, - "ghcr.io/sebst/devcontainer-features/pkgx:1": {} + "ghcr.io/sebst/devcontainer-features/pkgx:1": {}, + "ghcr.io/devcontainers-extra/features/apt-packages:1": { + "clean_ppas": true, + "preserve_apt_list": true, + "packages": "build-essential linux-libc-dev", + "ppas": "ppa:deadsnakes/ppa" + } }, - // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, - // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "git submodule update --init", - // Use 'postAttachCommand' to run commands after the container is attached. "postAttachCommand": "pkgx install npx && npx -y runme run --filename README.md -t devcontainer -y" - // Configure tool-specific properties. // "customizations": {}, - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" }