Code Monkey home page Code Monkey logo

gxbuild's Introduction

gxbuild

gxbuild is a build system for applications using C and raylib.

Features

  • Supports building for Windows, Linux, Web and Android
  • Uses shell scripts, making it easy to run on all platforms with minimal prior setup
  • Automates most of the setup process: installing dependencies, downloading and compiling raylib

Setting up

  1. Change the options in config.sh to your liking (app name, compiler flags).
  2. If you're on Windows, download w64devkit. Make sure you get a release zip, not the source code. Extract the archive somewhere and run w64devkit.exe. On Linux, just open a terminal.
  3. Follow the below instructions for the platform you want to build for.

Desktop

  1. Run ./setup.sh to set up the project.
  2. Run ./build.sh to compile the project.

Web

  1. Run TARGET=Web ./setup.sh to set up the project. You will need about 1 GB of free space.
  2. Run TARGET=Web ./build.sh to compile the project.

Android

  1. Download Java and extract it somewhere. On Linux, you can also install Java using a package manager (make sure you get the JDK, not just the JRE).
  2. Change the Java path in config.sh.
  3. Run TARGET=Android ./setup.sh to set up the project. You will need about 5 GB of free space.
  4. Run TARGET=Android ./build.sh to compile the project.

Compiling for Windows from Linux

  1. Install mingw-w64 using your package manager.
  2. Run TARGET=Windows_NT ./setup.sh to set up the project.
  3. Run TARGET=Windows_NT ./build.sh to compile the project.

Notes

raylib currently has some issues on Web and Android platforms, here I've documented some of the issues I've found when creating the CaveScroller game for the raylib 5K gamejam. If you have any other issues, you can also check the raylib issue tracker for Web and Android.

Web

Save/LoadStorageValue

SaveStorageValue and LoadStorageValue save their values in a storage.data file internally managed by raylib. raylib on Web (emscripten) does not have a persistent file system, any files created during the runtime of the application are not saved when the user reloads the page.

However, web browsers have a feature called local storage which allows saving values persistently. You can add this to your code to allow saving and loading values on Web, just use the save and load functions like you would use SaveStorageValue and LoadStorageValue:

#ifdef PLATFORM_WEB
	#include <emscripten/emscripten.h>
	#define save(i, v) emscripten_run_script(TextFormat("localStorage.setItem(\"%d\", %d);", i, v))
	#define load(i) emscripten_run_script_int(TextFormat("localStorage.getItem(\"%d\");", i))
#else
	#define save SaveStorageValue
	#define load LoadStorageValue
#endif

Android

File system

Currently the file system is not accessible on Android. Trying to load any file outside the assets folder results in Failed to open file. This means that any user created files cannot be loaded, and SaveStorageValue/LoadStorageValue don't work.

Assets such as images and sounds that are bundled into the APK file can still be loaded. gxbuild automatically bundles everything in the assets folder into the APK. Note that the assets folder is only created after running the setup.sh script.

Assets folder

On Android, the default working directory for loading assets is the assets folder. On other platforms, it is usually the directory containing the executable. To make sure your assets are loaded from the same directory on all platforms, you can do this:

#ifndef PLATFORM_ANDROID
	ChangeDirectory("assets");
#endif

myTexture = LoadTexture("texture.png");
mySound = LoadSound("sound.wav");
myFont = LoadFont("font.ttf");

#ifndef PLATFORM_ANDROID
	ChangeDirectory("..");
#endif

GitHub Actions

GitHub Actions can be set up to automatically build your project when you push new changes, and give your users executables without them having to compile your project. Create a new file called .github/workflows/main.yml and paste these contents:

name: Build project
on: push

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      
      - name: Setup build environment
        run: |
          sudo apt update
          sudo apt install mingw-w64
          ./setup.sh
          TARGET=Windows_NT ./setup.sh
          
      - name: Build project
        run: |
          ./build.sh
          TARGET=Windows_NT ./build.sh

      - uses: actions/[email protected]
        with:
          name: game-linux
          path: game
            
      - uses: actions/[email protected]
        with:
          name: game-windows
          path: game.exe

Replace all instances of game with your project's name, the same as defined in config.sh. This will only build for Windows and Linux.

Note that by default, users must be logged in to GitHub to download the executables (artifacts). You can give your users a link like this to let them download without logging in: https://nightly.link/YOURNAME/YOURREPO/workflows/main/main. You can read more about this here.

gxbuild's People

Contributors

gtrxac avatar seprab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gxbuild's Issues

source command fails on w64devkit

On w64devkit (busybox?) source config.sh does not work:

./setup.sh: source: line 14: config.sh: not found

After changing source config.sh to source ./config.sh in setup.sh and build.sh, everything worked fine.
(Note: the other source commands, e.g. source android/setup.sh worked fine, do not need to be modified.)

which JDK version

The config.sh has the default/example JDK set to 18, but Android build script expects a file rt.jar which was apparently removed in JDK 14?
EDIT: Apparently it was removed in JDK 9? Does that mean JDK 8 is required? (raylib itself links to JDK 13)

emcc: Nothing to do

Hi!
I ran TARGET=Web ./setup.sh, which completed successfully, but when I run TARGET=Web ./build.sh, emcc says there's "Nothing to do!", even though I think I set the SRC variable correctly. I run Pop!_OS 22.04 LTS with bash.

eric@pop-os:~/Documents/gxbuild$ TARGET=Web ./build.sh
Setting up EMSDK environment (suppress these messages with EMSDK_QUIET=1)
Adding directories to PATH:
PATH += /home/eric/Documents/gxbuild/emsdk
PATH += /home/eric/Documents/gxbuild/emsdk/upstream/emscripten
PATH += /home/eric/Documents/gxbuild/emsdk/node/14.18.2_64bit/bin

Setting environment variables:
PATH = /home/eric/Documents/gxbuild/emsdk:/home/eric/Documents/gxbuild/emsdk/upstream/emscripten:/home/eric/Documents/gxbuild/emsdk/node/14.18.2_64bit/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
EMSDK = /home/eric/Documents/gxbuild/emsdk
EMSDK_NODE = /home/eric/Documents/gxbuild/emsdk/node/14.18.2_64bit/bin/node
Nothing to do!
emcc: error: '/home/eric/Documents/gxbuild/emsdk/upstream/emscripten/tools/file_packager game.data --from-emcc --export-name=Module --preload assets' failed (returned 1)

Here is my config.sh: (I didn't change anything, I think it isn't necessary if I don't want to build for Android.)

#!/bin/bash
# ______________________________________________________________________________
#
#  Build options
#  This script is sourced by build.sh and setup.sh, no need to run it yourself
# ______________________________________________________________________________
#
# Executable name, extension is added depending on target platform.
NAME=game

# Files to compile. You can add multiple files by separating by spaces.
SRC="src/*.c"

# Platform, one of Windows_NT, Linux, Web, Android. Defaults to your OS.
# This can be set from the command line: TARGET=Android ./build.sh
[[ -z "$TARGET" ]] && TARGET=$(uname)

# Compiler flags.
# This can be set from the command line: FLAGS="-Ofast" ./build.sh
[[ -z "$FLAGS" ]] && FLAGS=""

# Compiler flags for release and debug mode
# To set debug mode, run: DEBUG=1 ./build.sh
RELEASE_FLAGS="-Os -flto -s"
DEBUG_FLAGS="-DDEBUG -O0 -g -Wall -Wextra -Wpedantic"

# ______________________________________________________________________________
#
#  Build options for Android
# ______________________________________________________________________________
#
# Path to the Java JDK. This folder should contain a bin folder which has javac
# and some other tools. On Linux, if Java was installed from a package manager,
# the Java path should be somewhere in /usr/lib/jvm.
JAVA=/usr/lib/jvm/java-18-openjdk-amd64

# The developer and package name for the app: com.$DEV_NAME.$PKG_NAME
DEV_NAME=raylib
PKG_NAME=$NAME

# The name of the app shown in the launcher.
APP_NAME=Game

# App version, version code should be incremented by 1 and version name is the
# human readable version.
VERSION_CODE=1
VERSION_NAME=1.0

# What Android API version to target. API_VERSION 29 (Android 10) or above is
# recommended. With an API_VERSION of 23 (Android 6) and up, versions below 23
# are not supported, so the MIN_API_VERSION should be set to 23. To support
# versions 19 (4.4) to 22 (5.1), both the API_VERSION and MIN_API_VERSION should
# be set to 19.
API_VERSION=31
MIN_API_VERSION=23

# The app's screen orientation, portrait or landscape.
SCREEN_ORIENTATION=landscape

# Architectures to build for. armeabi-v7a works for most devices.
ABIS="armeabi-v7a x86"

# Paths for Android SDK/NDK. Don't change unless you already have an SDK
# installation and you know what you're doing.
SDK=$(pwd)/android/sdk/$(uname)
NDK=$(pwd)/android/ndk/$(uname)/android-ndk-r23b
BUILD=$(pwd)/android/build

case $(uname) in
	"Windows_NT") TOOLCHAIN_OS="windows-x86_64";;
	"Linux") TOOLCHAIN_OS="linux-x86_64";;
esac

BUILD_TOOLS_VERSION=29.0.3
BUILD_TOOLS=$SDK/build-tools/$BUILD_TOOLS_VERSION
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$TOOLCHAIN_OS
NATIVE_APP_GLUE=$NDK/sources/android/native_app_glue
AR=$TOOLCHAIN/bin/llvm-ar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.