-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First working prototype for exposing functions to C * crunch64_decompress_yaz0_get_dst_buffer_size * Bindings for compressing yaz0 * cleanup cod * fix lib and bin * makefile for building the C tests * c bindings for yay0 * Tests for Yay0 bindings * Update the yaz0 test * _bound * CI for testing C bindings * More Result * u8_vec_from_pointer_array and set_pointer_array_from_u8_array * Cleanup yaz0 * yay0 cleanup * fix * Testing packaging C libs * maybe fix ci * ¿¿ * idk * hopefully fix * install target * more fixes * does this work? * maybe? * sad * redundant path? * suffering * asd * CI: Enable building cdylib and compress format based on target arch * more customization * oops * fix * fix errors on some archs * Fix * Package readme and license in C libs * Try to build cdylib on other targets * Add x86_64-pc-windows-msvc * disable cdylib for windows msvc * a * Add x86_64-pc-windows-gnullvm * yeet x86_64-pc-windows-gnullvm * Fix msvc * Disable cdylib * #ifdef __cplusplus extern "C" * add windows weird stuff before i forget * Propagate errors to C * Run C tests against all test cases * Enable Rust tests to run on other branches * Fix clippy warnings * fmt * reorganize stuff * remove * Put C bindings behind a feature * Move common test code to utils.c * publish release ci * instructions on readme * size_for_compressed_buffer
- Loading branch information
1 parent
2f2ba45
commit fe1780a
Showing
26 changed files
with
1,416 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: C bindings | ||
|
||
on: [push, pull_request] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
test-c-bindings: | ||
name: Test C bindings | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Make C test programs | ||
run: make -C c_bindings BUILD_MODE=release | ||
|
||
- name: Test Yay0 | ||
run: ./c_bindings/tests/test_yay0.sh | ||
|
||
- name: Test Yaz0 | ||
run: ./c_bindings/tests/test_yaz0.sh | ||
|
||
release: | ||
name: Release ${{ matrix.crate-type }} for ${{ matrix.target }} | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
target: [x86_64-pc-windows-gnu, x86_64-pc-windows-msvc, x86_64-apple-darwin, x86_64-unknown-linux-musl, x86_64-unknown-linux-gnu] | ||
crate-type: [staticlib] | ||
include: | ||
- target: x86_64-pc-windows-gnu | ||
archive: zip | ||
- target: x86_64-pc-windows-msvc | ||
archive: zip | ||
- target: x86_64-apple-darwin | ||
archive: zip | ||
- target: x86_64-unknown-linux-musl | ||
archive: tar.gz | ||
- target: x86_64-unknown-linux-gnu | ||
archive: tar.gz | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
targets: ${{ matrix.target }} | ||
|
||
- name: Build lib | ||
run: cargo rustc --manifest-path lib/Cargo.toml --lib --features c_bindings --release --crate-type ${{ matrix.crate-type }} --target ${{ matrix.target }} | ||
|
||
- name: Print built files | ||
run: | | ||
tree target/${{ matrix.target }}/release | ||
- name: Move files for packaging | ||
run: | | ||
mkdir -p package/lib package/include | ||
cp target/${{ matrix.target }}/release/libcrunch64.a package/lib/ || cp target/${{ matrix.target }}/release/crunch64.lib package/lib/ | ||
cp -r c_bindings/include/* package/include/ | ||
cp LICENSE package/crunch64.LICENSE | ||
cp README.md package/crunch64.README.md | ||
tree package | ||
- name: Package .tar.gz | ||
if: matrix.archive == 'tar.gz' | ||
run: | | ||
cd package && tar -czf ../crunch64-${{ matrix.crate-type }}-${{ matrix.target }}.tar.gz * | ||
- name: Package .zip | ||
if: matrix.archive == 'zip' | ||
run: | | ||
cd package && zip -r ../crunch64-${{ matrix.crate-type }}-${{ matrix.target }}.zip * | ||
- name: Upload .tar.gz archive | ||
if: matrix.archive == 'tar.gz' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: crunch64-${{ matrix.crate-type }}-${{ matrix.target }} | ||
path: | | ||
crunch64-${{ matrix.crate-type }}-${{ matrix.target }}.tar.gz | ||
if-no-files-found: error | ||
|
||
- name: Upload .zip archive | ||
if: matrix.archive == 'zip' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: crunch64-${{ matrix.crate-type }}-${{ matrix.target }} | ||
path: | | ||
crunch64-${{ matrix.crate-type }}-${{ matrix.target }}.zip | ||
if-no-files-found: error | ||
|
||
- name: Publish .tar.gz release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') && matrix.archive == 'tar.gz' | ||
with: | ||
files: crunch64-${{ matrix.crate-type }}-${{ matrix.target }}.tar.gz | ||
|
||
- name: Publish .zip release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') && matrix.archive == 'zip' | ||
with: | ||
files: crunch64-${{ matrix.crate-type }}-${{ matrix.target }}.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,36 +2,41 @@ on: | |
release: | ||
types: [created] | ||
jobs: | ||
release: | ||
name: release ${{ matrix.target }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- target: x86_64-pc-windows-gnu | ||
archive: zip | ||
- target: x86_64-unknown-linux-musl | ||
archive: tar.gz | ||
- target: x86_64-apple-darwin | ||
archive: zip | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Compile and release | ||
uses: rust-build/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
RUSTTARGET: ${{ matrix.target }} | ||
ARCHIVE_TYPES: ${{ matrix.archive }} | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
override: true | ||
- uses: katyo/publish-crates@v2 | ||
with: | ||
registry-token: ${{ secrets.CRATE_AUTH_TOKEN }} | ||
release: | ||
name: release ${{ matrix.target }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- target: x86_64-pc-windows-gnu | ||
archive: zip | ||
- target: x86_64-pc-windows-msvc | ||
archive: zip | ||
- target: x86_64-apple-darwin | ||
archive: zip | ||
- target: x86_64-unknown-linux-musl | ||
archive: tar.gz | ||
- target: x86_64-unknown-linux-gnu | ||
archive: tar.gz | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Compile and release | ||
uses: rust-build/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
RUSTTARGET: ${{ matrix.target }} | ||
ARCHIVE_TYPES: ${{ matrix.archive }} | ||
|
||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
override: true | ||
- uses: katyo/publish-crates@v2 | ||
with: | ||
registry-token: ${{ secrets.CRATE_AUTH_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ target/ | |
*.bin | ||
*.Yay0 | ||
*.Yaz0 | ||
*.elf | ||
|
||
.vscode/settings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"${workspaceFolder}/**", | ||
"${workspaceFolder}/c_bindings/include" | ||
], | ||
"defines": [], | ||
"compilerPath": "/usr/bin/clang", | ||
"intelliSenseMode": "linux-clang-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "test_yay0.elf", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/c_bindings/tests/test_yay0.elf", | ||
"args": ["${workspaceFolder}/test_data/ground.png", "${workspaceFolder}/test_data/ground.png.Yay0"], | ||
"stopAtEntry": false, | ||
"cwd": "${workspaceFolder}", | ||
"environment": [], | ||
"externalConsole": false, | ||
"MIMode": "gdb", | ||
"setupCommands": [ | ||
{ | ||
"description": "Enable pretty-printing for gdb", | ||
"text": "-enable-pretty-printing", | ||
"ignoreFailures": true | ||
}, | ||
{ | ||
"description": "Set Disassembly Flavor to Intel", | ||
"text": "-gdb-set disassembly-flavor intel", | ||
"ignoreFailures": true | ||
} | ||
] | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[workspace] | ||
members = [ | ||
"lib", | ||
"cli", | ||
] | ||
members = ["lib", "cli"] | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# crunch64 | ||
|
||
## C bindings | ||
|
||
This library provides bindings to call this library from C code. They are available on the [releases](https://github.com/decompals/crunch64/releases) tab. | ||
|
||
To build said bindings from source, enable the `c_bindings` Rust feature: | ||
|
||
```bash | ||
cargo build --lib --features c_bindings | ||
``` | ||
|
||
Headers are located at [c_bindings/include](c_bindings/include). | ||
|
||
### Windows executables | ||
|
||
Due to Rust requirements, linking the C bindings of this library when building a C program adds extra library dependencies. Those libraries are the following: | ||
|
||
```plain_text | ||
-lws2_32 -lntdll -lbcrypt -ladvapi32 -luserenv | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Either `debug` or `release` | ||
BUILD_MODE ?= debug | ||
|
||
CC := gcc | ||
LIB := ../target/$(BUILD_MODE)/libcrunch64.a | ||
|
||
CSTD := -std=c11 | ||
ifeq ($(BUILD_MODE), debug) | ||
CFLAGS ?= -O0 -g3 | ||
else | ||
CFLAGS ?= -Os | ||
endif | ||
IINC := -I include | ||
WARNINGS := -Wall -Wextra -Wshadow -Werror | ||
|
||
|
||
C_BINDINGS_TESTS := $(wildcard tests/test_*.c) | ||
C_BINDINGS_ELFS := $(C_BINDINGS_TESTS:.c=.elf) | ||
|
||
all: $(C_BINDINGS_ELFS) | ||
|
||
clean: | ||
$(RM) -rf $(C_BINDINGS_ELFS) tests/*.elf | ||
|
||
.PHONY: all clean | ||
.DEFAULT_GOAL := all | ||
|
||
CARGO_FLAGS ?= | ||
ifneq ($(BUILD_MODE), debug) | ||
CARGO_FLAGS += --release | ||
endif | ||
$(shell cargo build --lib --features c_bindings $(CARGO_FLAGS)) | ||
|
||
|
||
%.elf: %.c $(LIB) | ||
$(CC) $(CSTD) $(CFLAGS) $(IINC) $(WARNINGS) -o $@ tests/utils.c $< -L ../target/$(BUILD_MODE) -Wl,-Bstatic -l crunch64 -Wl,-Bdynamic | ||
|
||
# Print target for debugging | ||
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef CRUNCH64_H | ||
#define CRUNCH64_H | ||
#pragma once | ||
|
||
#include "crunch64/error.h" | ||
#include "crunch64/yay0.h" | ||
#include "crunch64/yaz0.h" | ||
|
||
#endif |
Oops, something went wrong.