Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Dr-Nekoma/lyceum into issue-60
Browse files Browse the repository at this point in the history
  • Loading branch information
z-silver committed Jan 7, 2025
2 parents d4c1fbb + bc24e08 commit 84c8beb
Show file tree
Hide file tree
Showing 21 changed files with 583 additions and 381 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "[Build] Client"
name: "[Client] Build"

on:
push:
Expand Down Expand Up @@ -42,8 +42,9 @@ jobs:

- name: "[Client] Build"
run: |
nix develop .#ci --impure -c just client-build-ci
nix build .#client
- name: "[Client] Tests"
run: |
nix develop .#ci --impure -c just client-build-ci
nix develop .#ci --impure -c just client-test-ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "[Build] Server"
name: "[Server] Build"

on:
push:
Expand Down Expand Up @@ -72,8 +72,8 @@ jobs:
- name: "[Database] Check Migrations"
run: |
nix develop .#ci --impure -c just db-up
nix develop .#ci --impure -c just dbu
- name: "[Database] Check Input Generation"
run: |
nix develop .#ci --impure -c just db-input
nix develop .#ci --impure -c just dbi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "[Deploy] Server"
name: "[Server] Deploy"

on:
push:
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/server_dialyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "[Server] Dialyzer"

on:
push:
branches: [ "master" ]
paths:
- .github/workflows/**
- server/**
- flake.nix
- flake.lock
pull_request:
branches: [ "master" ]
paths:
- .github/workflows/**
- server/**
- flake.nix
- flake.lock

permissions:
contents: read

jobs:
dialyzer:
name: Dialyzer
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true

- name: Install Nix
uses: cachix/install-nix-action@v26
with:
# Mostly to avoid GitHub rate limiting
extra_nix_config: |
access-tokens = github.com=${{ github.token }}
- name: Install Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: "[Server] Check Dialyzer"
run: |
nix develop .#ci --impure -c just d
72 changes: 54 additions & 18 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#+TITLE: Lyceum 🏛️

#+html: <a href="https://builtwithnix.org"><img alt="built with nix" src="https://builtwithnix.org/badge.svg" /></a><br>
#+html: <a href="https://github.com/Dr-Nekoma/lyceum/actions/workflows/build_client.yml"> <img alt="[Build] Client" src="https://github.com/Dr-Nekoma/lyceum/actions/workflows/build_client.yml/badge.svg" /></a>
#+html: <a href="https://github.com/Dr-Nekoma/lyceum/actions/workflows/build_server.yml"> <img alt="[Build] Server Client" src="https://github.com/Dr-Nekoma/lyceum/actions/workflows/build_server.yml/badge.svg" /></a>
#+html: <a href="https://github.com/Dr-Nekoma/lyceum/actions/workflows/deploy_server.yml"> <img alt="[Deploy] Server Status" src="https://github.com/Dr-Nekoma/lyceum/actions/workflows/deploy_server.yml/badge.svg" /></a>
#+html: <a href="https://github.com/Dr-Nekoma/lyceum/actions/workflows/client_build.yml"> <img alt="[Client] Build" src="https://github.com/Dr-Nekoma/lyceum/actions/workflows/client_build.yml/badge.svg" /></a><br>
#+html: <a href="https://github.com/Dr-Nekoma/lyceum/actions/workflows/server_build.yml"> <img alt="[Server] Build" src="https://github.com/Dr-Nekoma/lyceum/actions/workflows/server_build.yml/badge.svg" /></a>
#+html: <a href="https://github.com/Dr-Nekoma/lyceum/actions/workflows/server_dialyzer.yml"> <img alt="[Server] Dialyzer" src="https://github.com/Dr-Nekoma/lyceum/actions/workflows/server_dialyzer.yml/badge.svg" /></a>
#+html: <a href="https://github.com/Dr-Nekoma/lyceum/actions/workflows/server_deploy.yml"> <img alt="[Server] Deploy" src="https://github.com/Dr-Nekoma/lyceum/actions/workflows/server_deploy.yml/badge.svg" /></a>

* About

Expand All @@ -19,22 +20,14 @@ There are several ways to run this project, but they all leverage [[https://nixo
single [[https://devenv.sh/][devenv]] configured, that has all the tooling required to run this project,
it also includes postgres.

** Testing the Game (DEMO)

1. ~nix develop --impure~
2. ~devenv up~ to launch a local ~postgres~
3. ~just db-reset~ or ~db-reset~, to initialize ~postgres~ for local development
5. ~server~ (or ~./result/bin/server foreground~ if you want to run the pure nix build)
6. followed by ~client-release~
7. Once you get the client to launch, connect to ~localhost~ and you can try
playing with any of the local credentials [[https://github.com/Dr-Nekoma/lyceum/blob/master/server/database/main.input.sql#L3][here]].

** Development Shell

To enter a development shell we assume you have at least [[https://nixos.org/][Nix]] installed:

#+BEGIN_SRC shell
# To enter the developmet shell
nix develop --impure
# To spawn postgres
# To spawn postgres (for instance)
devenv up -d
#+END_SRC

Expand All @@ -52,16 +45,59 @@ to migrate the local dababase, you can use ~just db-up~ or ~db-up~.
You can also build the server and related OCI images with Nix.

#+BEGIN_SRC shell
nix build .#server
nix build .#server
#+END_SRC

if you prefer running a container for the server:

#+BEGIN_SRC shell
nix build .#buildImage
docker load < ./result
docker container run --network=host lyceum:latest
nix build .#buildImage
docker load < ./result
docker container run --network=host lyceum:latest
#+END_SRC

or if you want to build the ~zig~ client, run ~nix build .#client~.

** Testing the Game

To run our DEMO you need to follow the steps in this particular order:

1. ~nix develop --impure~ (to enter a development shell)
2. ~devenv up~ to launch a local ~postgres~
3. ~just db-reset~ or ~db-reset~, to initialize ~postgres~ for local development
4. Run the ~erlang~ backend in a separate shell with either:

#+begin_src shell
server
# or
just server
# or if you want a pure build
nix build .#server
./result/bin/server foreground
#+end_src

5. Followed by running the ~zig~ client in a third shell with either:

#+begin_src shell
client-release
# or
just client-release
# or if you prefer a pure build
nix build .#client
./result/bin/lyceum-client
#+end_src

*Addendum*: We got [[https://github.com/Dr-Nekoma/lyceum/pull/83#issuecomment-2550476288][reports]] that (sometimes) non-NixOS users will have to rely on[[https://github.com/nix-community/nixGL][ nixGL]].

#+begin_src shell
nix run --impure github:nix-community/nixGL -- ./result/bin/lyceum-client
#+end_src

6. Once you get the client to launch, connect to ~localhost~ and you can try
playing with any of the local credentials [[https://github.com/Dr-Nekoma/lyceum/blob/master/server/database/main.input.sql#L3][here]].

** Deployment

This game is deployed in our [[https://github.com/Dr-Nekoma/trashcan][NixOS server]].

* Assets
Expand Down
14 changes: 14 additions & 0 deletions client/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ pub fn build(b: *std.Build) !void {
exe.root_module.addImport("zerl", zerl.module("zerl"));
}

const assets = b.addInstallDirectory(.{
.source_dir = b.path("assets"),
.install_dir = .prefix,
.install_subdir = "assets",
});

exe.step.dependOn(&assets.step);

// https://ziglang.org/learn/build-system/#conditional-compilation
const assets_opt = b.option([]const u8, "assets", "custom path for the assets directory") orelse "./assets";
const options = b.addOptions();
options.addOption([]const u8, "assets", assets_opt);
exe.root_module.addOptions("build_options", options);

if (b.lazyImport(@This(), "zerl")) |zerl_build| {
if (std.posix.getenv("LIBRARY_PATH")) |lib_path| {
try zerl_build.add_erlang_paths(b, lib_path);
Expand Down
2 changes: 1 addition & 1 deletion client/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.{
// the name of your project
.name = "lyceum-client",
.version = "0.0.1",
.version = "0.1.0",
.dependencies = .{
.@"raylib-zig" = .{
.url = "https://github.com/Not-Nik/raylib-zig/archive/58df62807f62bef1db79538d04b37b9f79909d0a.tar.gz",
Expand Down
3 changes: 2 additions & 1 deletion client/src/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const rl = @import("raylib");
const rm = rl.math;
const std = @import("std");
const GameState = @import("game/state.zig");
const build_options = @import("build_options");

const base_filepath = "./assets/";
const base_filepath = build_options.assets;

fn load(
comptime T: type,
Expand Down
121 changes: 85 additions & 36 deletions client/zon-deps.nix
Original file line number Diff line number Diff line change
@@ -1,48 +1,97 @@
# generated by zon2nix (https://github.com/Cloudef/zig2nix)

{ lib, linkFarm, fetchurl, fetchgit, runCommandLocal, zig, name ? "zig-packages" }:
{
lib,
linkFarm,
fetchurl,
fetchgit,
runCommandLocal,
zig,
name ? "zig-packages",
}:

with builtins;
with lib;

let
unpackZigArtifact = { name, artifact }: runCommandLocal name {
nativeBuildInputs = [ zig ];
} ''
hash="$(zig fetch --global-cache-dir "$TMPDIR" ${artifact})"
mv "$TMPDIR/p/$hash" "$out"
chmod 755 "$out"
'';
unpackZigArtifact =
{ name, artifact }:
runCommandLocal name
{
nativeBuildInputs = [ zig ];
}
''
hash="$(zig fetch --global-cache-dir "$TMPDIR" ${artifact})"
mv "$TMPDIR/p/$hash" "$out"
chmod 755 "$out"
'';

fetchZig = { name, url, hash }: let
artifact = fetchurl { inherit url hash; };
in unpackZigArtifact { inherit name artifact; };
fetchZig =
{
name,
url,
hash,
}:
let
artifact = fetchurl { inherit url hash; };
in
unpackZigArtifact { inherit name artifact; };

fetchGitZig = { name, url, hash }: let
parts = splitString "#" url;
url_base = elemAt parts 0;
url_without_query = elemAt (splitString "?" url_base) 0;
rev_base = elemAt parts 1;
rev = if match "^[a-fA-F0-9]{40}$" rev_base != null then rev_base else "refs/heads/${rev_base}";
in fetchgit {
inherit name rev hash;
url = url_without_query;
deepClone = false;
};

fetchZigArtifact = { name, url, hash }: let
parts = splitString "://" url;
proto = elemAt parts 0;
path = elemAt parts 1;
fetcher = {
"git+http" = fetchGitZig { inherit name hash; url = "http://${path}"; };
"git+https" = fetchGitZig { inherit name hash; url = "https://${path}"; };
http = fetchZig { inherit name hash; url = "http://${path}"; };
https = fetchZig { inherit name hash; url = "https://${path}"; };
file = unpackZigArtifact { inherit name; artifact = /. + path; };
fetchGitZig =
{
name,
url,
hash,
}:
let
parts = splitString "#" url;
url_base = elemAt parts 0;
url_without_query = elemAt (splitString "?" url_base) 0;
rev_base = elemAt parts 1;
rev = if match "^[a-fA-F0-9]{40}$" rev_base != null then rev_base else "refs/heads/${rev_base}";
in
fetchgit {
inherit name rev hash;
url = url_without_query;
deepClone = false;
};
in fetcher.${proto};
in linkFarm name [

fetchZigArtifact =
{
name,
url,
hash,
}:
let
parts = splitString "://" url;
proto = elemAt parts 0;
path = elemAt parts 1;
fetcher = {
"git+http" = fetchGitZig {
inherit name hash;
url = "http://${path}";
};
"git+https" = fetchGitZig {
inherit name hash;
url = "https://${path}";
};
http = fetchZig {
inherit name hash;
url = "http://${path}";
};
https = fetchZig {
inherit name hash;
url = "https://${path}";
};
file = unpackZigArtifact {
inherit name;
artifact = /. + path;
};
};
in
fetcher.${proto};
in
linkFarm name [
{
name = "1220df9aa89d657f5dca24ab0ac3d187f7a992a4d27461fd9e76e934bf0670ca9a90";
path = fetchZigArtifact {
Expand Down Expand Up @@ -75,4 +124,4 @@ in linkFarm name [
hash = "sha256-9dMtMC5c+nn6oYYmX/Xc8xIwG9m9/9Wym5lraK3BeI8=";
};
}
]
]
Loading

0 comments on commit 84c8beb

Please sign in to comment.