Skip to content

Commit

Permalink
feat: begin
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Nov 28, 2023
1 parent 2cef9db commit 8dcc552
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 2 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build

on:
push:
paths:
- '.github/workflows/build.yml'
- 'src/**/*'
- 'Cargo.toml'
- 'package.sh'
- 'package.ps1'
pull_request:
paths:
- '.github/workflows/build.yml'
- 'src/**/*'
- 'Cargo.toml'
- 'package.sh'
- 'package.ps1'

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
build:
runs-on: ${{ matrix.platform }}

strategy:
fail-fast: false
matrix:
platform: [windows-latest, ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v2

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
./target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build --release

# - name: Package
# if: matrix.platform != 'windows-latest'
# run: chmod +x ./package.sh && ./package.sh
# env:
# LIB_FILE: ${{ matrix.platform != 'windows-latest' && 'lib' || '' }}file_metadata${{ matrix.platform == 'windows-latest' && '.dll' || matrix.platform == 'macos-latest' && '.dylib' || '.so' }}

# - name: Package
# if: matrix.platform == 'windows-latest'
# run: ./package.ps1
# env:
# LIB_FILE: ${{ matrix.platform != 'windows-latest' && 'lib' || '' }}file_metadata${{ matrix.platform == 'windows-latest' && '.dll' || matrix.platform == 'macos-latest' && '.dylib' || '.so' }}

- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: lib-${{ matrix.platform }}
# Find exec based on platform
path: target/release/${{ matrix.platform != 'windows-latest' && 'lib' || '' }}file_metadata${{ matrix.platform == 'windows-latest' && '.dll' || matrix.platform == 'macos-latest' && '.dylib' || '.so' }}

45 changes: 45 additions & 0 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Code quality and formatting

on:
push:
paths:
- '.github/workflows/backend.yml'
- 'src/**'
- 'Cargo.toml'
pull_request:
paths:
- '.github/workflows/backend.yml'
- 'src/**'
- 'Cargo.toml'

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
rustfmt:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions-rs/cargo@v1
with:
command: fmt
args: --manifest-path ./Cargo.toml --all -- --check

clippy:
runs-on: ${{ matrix.platform }}

strategy:
fail-fast: false
matrix:
platform: [windows-latest, ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v3

- uses: actions-rs/cargo@v1
with:
command: clippy
args: --manifest-path ./Cargo.toml --all -- -D warnings
66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test

on:
push:
paths:
- '.github/workflows/test.yml'
- 'src/**/*'
- 'Cargo.toml'
pull_request:
paths:
- '.github/workflows/test.yml'
- 'src/**/*'
- 'Cargo.toml'

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.platform }}

strategy:
fail-fast: false
matrix:
platform: [windows-latest, ubuntu-latest, macos-latest]

# Setup
steps:
- uses: actions/checkout@v2

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
./target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

# Build the library
- name: Build
run: cargo build --release

# Build test/test.c
- name: Build test
run: gcc -o test/testlib test/test.c -L target/release -lfile_metadata

# Run test/test.c
- name: Run
if: matrix.platform == 'macos-latest'
run: ./test/testlib

- name: Run
if: matrix.platform == 'ubuntu-latest'
run: LD_LIBRARY_PATH=target/release ./test/testlib

- name: Run
if: matrix.platform == 'windows-latest'
run: move target\release\file_metadata.dll file_metadata.dll && test\testlib.exe
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb


# Added by cargo

/target

# Test stuff
test/testlib*
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "gm-sysinfo"
version = "1.0.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
sysinfo = "0.29.11"
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# gms-sysinfo
Get memory, CPU, and someday GPU info within your GameMaker game.
<div align="center">
<h1>GM Sysinfo</h1>
<p>
Profile your game, and get it's (and the systems) resource usage!
</p>
</div>

# Examples

Below are some basic examples of the functionality in this extension

## Display memory usage
```gml
// Get max memory of the system
var max_mem = sysinfo_sys_mem_max();

// Get the memory usage of the game
var mem = sysinfo_mem_usage();

// Display the cur / max (pct%)
var max_mb = max_mem / 1024 / 1024;
var mem_mb = mem / 1024 / 1024;

draw_text(0, 0, string(mem_mb) + " / " + string(max_mb) + " (" + string(mem / max_mem * 100) + "%)");
```
## Display CPU usage
```gml
// Get the CPU and memory usage of the game
var cpu_name = sysinfo_cpu_name();
var cpu = sysinfo_cpu_usage();
// Display the %
draw_text(0, 0, cpu_name + ": " + string(cpu) + "%");
```

# TODO

- [ ] CPU usage
- [ ] Memory usage
- [ ] System name/hostname
- [ ] GPU usage(?)

# Documentation
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use sysinfo::{
System,
SystemExt,
Process,
ProcessExt,
Cpu,
CpuExt,
User,
UserExt
};
24 changes: 24 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>

// Include winbase on Windows
#include <stdio.h> /* defines FILENAME_MAX */
#ifdef _WIN32
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif

// Function prototypes for Rust functions
// extern

int main() {
printf("All tests passed!\n");

return 0;
}

0 comments on commit 8dcc552

Please sign in to comment.