Skip to content

Commit

Permalink
Updated gb and scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
wyvx committed Apr 3, 2024
1 parent 64c38ad commit 2697764
Show file tree
Hide file tree
Showing 37 changed files with 1,514 additions and 164 deletions.
33 changes: 20 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,42 @@ jobs:

strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
os: [ ubuntu-latest, macos-latest, macos-14, windows-latest ]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build
run: |
cd code
cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -B build.cmake -S .
cmake --build build.cmake --config ${{ env.BUILD_TYPE }} --parallel
# Output Linux: ./code/bin/<project>
# Output Windows: ./code/bin/${{ env.BUILD_TYPE }}/<project>.exe
run: ./build ${{ env.BUILD_TYPE }} clean
# Output Linux: ./code/build/bin/<project>
# Output Windows: ./code/build/bin/${{ env.BUILD_TYPE }}/<project>.exe

- name: Zip Linux
- name: Zip Ubuntu
if: matrix.os == 'ubuntu-latest'
env:
ZIP_NAME: ${{ env.PROJECT_NAME }}-linux-x64.tar.gz
BIN: code/bin
ZIP_NAME: ${{ env.PROJECT_NAME }}-ubuntu-x64.tar.gz
BIN: code/build/bin
PROJECT_BIN: ${{ env.PROJECT_NAME }}
run: |
tar -czf ${{ env.ZIP_NAME }} -C ${{ env.BIN }} ${{ env.PROJECT_BIN }}
gh release upload ${{ env.VERSION }} ${{ env.ZIP_NAME }} --clobber
- name: Zip macOS
- name: Zip macOS x64
if: matrix.os == 'macos-latest'
env:
ZIP_NAME: ${{ env.PROJECT_NAME }}-macos-x64.tar.gz
BIN: code/bin
BIN: code/build/bin
PROJECT_BIN: ${{ env.PROJECT_NAME }}
run: |
tar -czf ${{ env.ZIP_NAME }} -C ${{ env.BIN }} ${{ env.PROJECT_BIN }}
gh release upload ${{ env.VERSION }} ${{ env.ZIP_NAME }} --clobber
- name: Zip macOS aarch64
if: matrix.os == 'macos-14'
env:
ZIP_NAME: ${{ env.PROJECT_NAME }}-macos-aarch64.tar.gz
BIN: code/build/bin
PROJECT_BIN: ${{ env.PROJECT_NAME }}
run: |
tar -czf ${{ env.ZIP_NAME }} -C ${{ env.BIN }} ${{ env.PROJECT_BIN }}
Expand All @@ -91,7 +98,7 @@ jobs:
if: matrix.os == 'windows-latest'
env:
ZIP_NAME: ${{ env.PROJECT_NAME }}-windows-x64.zip
BIN: code/bin/${{ env.BUILD_TYPE }}
BIN: code/build/bin/${{ env.BUILD_TYPE }}
PROJECT_BIN: ${{ env.PROJECT_NAME }}.exe
run: |
tar -czf ${{ env.ZIP_NAME }} -C ${{ env.BIN }} ${{ env.PROJECT_BIN }}
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
.vscode/

# Build dirs.
build.cmake/
bin/
/code/build/
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# grun

![Version](https://img.shields.io/badge/Version-1.0.0-blue)
![Version](https://img.shields.io/badge/Version-1.1.0-blue)

This is a Gradle project runner. It builds, unpacks, and runs a Gradle project on the current console.
This is a Gradle project runner. It builds, unpacks, and runs a Gradle project on the current terminal.
Also allows `SIGINT` (Ctrl+C) to be captured by your application.
As opposed to Gradle's run task which doesn't attach a proper console and simply kills your app immediately on `SIGINT`.

## Use it!

Expand All @@ -22,24 +21,17 @@ As opposed to Gradle's run task which doesn't attach a proper console and simply

## Get it!

It is highly recommended that you build it yourself on your platform. *On my M1 Mac, the final binary is only 90KB.*
It is highly recommended that you build it yourself on your platform.

If you want a pre-compiled binary, check the [latest release](https://github.com/GlitchyByte/grun/releases) for your platform.
These are built using GitHub Actions on GitHub Runners and produce larger binaries than if you build locally.
If you want a pre-compiled binary for macOS, Windows, or Ubuntu, check the [latest release](https://github.com/GlitchyByte/grun/releases).
These are built using GitHub Actions on GitHub Runners.

## Build it!

Clone this repo.

Then, on macOS or Linux:
Clone this repo. Then:

./build MinSizeRel clean

On Windows:

cmake -DCMAKE_BUILD_TYPE=MinSizeRel -B build.cmake -S .
cmake --build build.cmake --config MinSizeRel --parallel

### Receive your tasty binary!

After building, `grun` executable is in the `bin` directory.
After building, `grun` executable is in the `code/bin` directory.
13 changes: 9 additions & 4 deletions _gcolors
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
# Copyright 2022-2023 GlitchyByte
# SPDX-License-Identifier: MIT

# _gcolors v1.2.0
# _gcolors v1.2.1

# Find out terminal color support.
readonly _tput_colors="$(tput colors 2>/dev/null)"
if [[ -n "${_tput_colors}" && "${_tput_colors}" != "0" ]]; then
readonly term_color_count="${_tput_colors}"
if [[ -t 1 ]]; then
readonly _tput_colors="$(tput colors 2>/dev/null)"
if [[ -n "${_tput_colors}" && "${_tput_colors}" != "0" ]]; then
readonly term_color_count="${_tput_colors}"
else
readonly term_color_count="0"
fi
else
readonly term_color_count="0"
fi
Expand Down Expand Up @@ -59,6 +63,7 @@ else
readonly cb_white=$(tput setab 7)
fi

# Pick from 256 colors.
color256() {
if [ "${term_color_count}" -lt "256" ]; then
echo ""
Expand Down
21 changes: 13 additions & 8 deletions build
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
# Copyright 2023 GlitchyByte
# Copyright 2023-2024 GlitchyByte
# SPDX-License-Identifier: MIT-0

# Builds project.

# [Setup]
set -u
set -e
set -u # Exit with an error if a variable is used without being set.
set -e # Exit if any command returns an error.
# Capture caller directory and script directory.
readonly calling_dir="${PWD}"
readonly script_dir="$(cd "$(dirname "$0")" && pwd)"
Expand Down Expand Up @@ -46,8 +46,13 @@ fi

# Dir constants.
cd "${script_dir}/code"
readonly buildConfigDir="build.cmake"
readonly binDir="bin"
readonly buildConfigDir="build/build.cmake"
readonly binDir="build/bin"

# Make sure build dir exists.
if [ ! -d "build" ]; then
mkdir "build"
fi

if [ "$clean" == "yes" ]; then
echo "${c_bold}${cf_black}Refreshing configuration...${c_reset}"
Expand All @@ -70,8 +75,8 @@ cmake -DCMAKE_BUILD_TYPE=${flavor} -B "${buildConfigDir}" -S .
echo "${c_bold}${cf_black}Building: ${cf_white}${flavor}${c_reset}"
cmake --build "${buildConfigDir}" --config ${flavor} --parallel

# Done!
echo "${cf_green}${c_bold}Build done!${c_reset}"

# [Teardown]
cd "${calling_dir}"

# Done!
echo "${cf_green}${c_bold}Build done!${c_reset}"
76 changes: 76 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
:: Copyright 2024 GlitchyByte
:: SPDX-License-Identifier: MIT-0

:: Builds project.

:: [Setup]
@echo off
setlocal enabledelayedexpansion
set "calling_dir=%CD%"
set "script_dir=%~dp0"
cd /d "%script_dir%"

:: [Main]
goto afterFuncs

:: Usage.
:printUsage
echo Usage: build [Debug^|Release^|MinSizeRel^|RelWithDebInfo] [clean]
cd /d "%calling_dir%"
exit /b 1

:afterFuncs

:: Accept 1 or more parameters.
if "%~1"=="" goto printUsage

:: If there is more than 1 parameter, the 2nd must be "clean".
if not "%~2"=="" (
if /i "%~2"=="clean" (
set "clean=yes"
) else (
goto printUsage
)
) else (
set "clean=no"
)

:: Capture valid flavor.
set "flavor=%~1"
if /i not "%flavor%"=="Debug" if /i not "%flavor%"=="Release" if /i not "%flavor%"=="MinSizeRel" if /i not "%flavor%"=="RelWithDebInfo" (
goto printUsage
)

:: Dir constants.
cd /d "%script_dir%\code"
set "buildConfigDir=build\build.cmake"
set "binDir=build\bin"

:: Make sure build dir exists.
if not exist "build" mkdir "build"

if "%clean%"=="yes" (
echo Refreshing configuration...
:: Remove build dir.
if exist "%buildConfigDir%" rmdir /s /q "%buildConfigDir%"
:: Clean bin dir.
if exist "%binDir%" (
rmdir /s /q "%binDir%"
mkdir "%binDir%"
)
)

:: Configure.
echo Configuring: !flavor!
cmake -DCMAKE_BUILD_TYPE=!flavor! -B "%buildConfigDir%" -S .

:: Build.
echo Building: !flavor!
cmake --build "%buildConfigDir%" --config %flavor% --parallel


:: [Teardown]
cd /d "%calling_dir%"

:: Done!
echo Build done!
27 changes: 23 additions & 4 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Copyright 2023 GlitchyByte
# Copyright 2023-2024 GlitchyByte
# SPDX-License-Identifier: MIT-0

cmake_minimum_required(VERSION 3.26)

set(IS_MACOS CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(IS_LINUX CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(IS_WINDOWS CMAKE_SYSTEM_NAME STREQUAL "Windows")

if (NOT CMAKE_BUILD_TYPE)
# Force MinSizeRel if no build type specified.
set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Type of build." FORCE)
Expand All @@ -20,14 +24,15 @@ message(STATUS "Platform: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)

# Set flags.
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if (${IS_LINUX} OR ${IS_MACOS})
# Linux and macOS.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto -ffunction-sections -fdata-sections")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
# Windows has not been tested.
elseif (${IS_WINDOWS})
# Windows.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /GL")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG")
Expand All @@ -41,8 +46,17 @@ endif ()
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "src/*.cpp")
add_executable(${APP} ${SOURCES})

#if (${IS_MACOS})
# target_link_libraries(${APP}
# PUBLIC "-framework CoreFoundation"
# PUBLIC "-framework CoreServices"
# )
#endif ()

# Add all h files in include dir.
target_include_directories(${APP} PRIVATE include)

# Minimize binary size.
if ((CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") AND
(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin"))
# Strip all remaining symbols and relocation information.
Expand All @@ -52,3 +66,8 @@ if ((CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRe
COMMAND strip $<TARGET_FILE:${APP}>
)
endif ()

# Add test project if CLion build for code insight.
if (CLION_BUILD)
add_subdirectory(test)
endif ()
2 changes: 1 addition & 1 deletion code/include/GradleParams.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 GlitchyByte
// Copyright 2023-2024 GlitchyByte
// SPDX-License-Identifier: Apache-2.0

#pragma once
Expand Down
39 changes: 35 additions & 4 deletions code/include/gb.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
// Copyright 2023 GlitchyByte
// Copyright 2023-2024 GlitchyByte
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <cstdint>

#ifdef __APPLE__
#define GB_IS_MACOS
#endif
#ifdef __linux__
#define GB_IS_LINUX
#endif
#ifdef _WIN32
#define GB_IS_WINDOWS
#endif

//#define GB_HASH
#define GB_STRINGS
#define GB_CONSOLE
#define GB_TERMINAL
//#define GB_FUNCTIONS
//#define GB_FILES
#define GB_PROCESS
#define GB_REPLACEABLE_VARS
//#define GB_SHUTDOWN_MONITOR
//#define GB_CONCURRENT
// #define GB_TASK
//#define GB_DIRECTORY_WATCHER

#include "gb/constants.h"
#ifdef GB_HASH
#include "gb/hash.h"
#endif
#ifdef GB_STRINGS
#include "gb/strings.h"
#ifdef GB_CONSOLE
#include "gb/console.h"
#ifdef GB_TERMINAL
#include "gb/terminal.h"
#endif
#endif
#ifdef GB_FUNCTIONS
#include "gb/functions.h"
#endif
#ifdef GB_FILES
#include "gb/files.h"
#endif
Expand All @@ -30,3 +52,12 @@
#ifdef GB_SHUTDOWN_MONITOR
#include "gb/ShutdownMonitor.h"
#endif
#ifdef GB_CONCURRENT
#ifdef GB_TASK
#include "gb/concurrent/Task.h"
#include "gb/concurrent/TaskRunner.h"
#endif
#endif
#ifdef GB_DIRECTORY_WATCHER
#include "gb/DirectoryWatcher.h"
#endif
Loading

0 comments on commit 2697764

Please sign in to comment.