diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1f7acfa..d9eddb7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,11 +16,17 @@ jobs: build: [macos, windows, linux] include: - build: linux + rustflags: "" target-bin: 'cusf_launcher.x86_64' + target-triple: x86_64-unknown-linux-gnu - build: macos + rustflags: "" target-bin: 'cusf_launcher.dmg' + target-triple: x86_64-apple-darwin - build: windows + rustflags: "-C linker=/usr/bin/x86_64-w64-mingw32-gcc" target-bin: 'cusf_launcher.exe' + target-triple: x86_64-pc-windows-gnu steps: - uses: actions/checkout@v3 @@ -34,6 +40,16 @@ jobs: - name: Verify Setup run: godot --version + - name: Install latest stable Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + target: ${{ matrix.target-triple }} + + - name: Install mingw-w64 + run: sudo apt install mingw-w64 + if: ${{ matrix.target-triple == 'x86_64-pc-windows-gnu' }} + - name: Import certificate to Keychain if: ${{ matrix.build == 'macos' }} run: | @@ -61,6 +77,14 @@ jobs: - name: Initialize godot cache run: python3 .github/scripts/godot_ci_cache.py + - name: Build rust extensions + run: | + pushd cusf_launcher_crypto + cargo build --release --target ${{ matrix.target-triple }} + popd + env: + RUSTFLAGS: ${{ matrix.rustflags }} + - name: Export build run: | name="${{fromJSON('{"windows": "Windows", "macos": "Mac", "linux": "Linux"}')[matrix.build] }}" diff --git a/README.md b/README.md index 5b43d3f..444c968 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,34 @@ # cusf_launcher -Requirements: -Godot v4.3 : -https://github.com/godotengine/godot/releases/tag/4.3-stable +## Requirements: +* Godot v4.3 : https://github.com/godotengine/godot/releases/tag/4.3-stable +* Rust/Cargo : https://rustup.rs/ -Command line build instructions: +If cross-compiling for Windows, mingw-64 is required. -Linux: +## Command line build instructions: -`godot --headless --path cusf_launcher/ --export-release "Linux" cusf_launcher.x86_64` +Linux: +``` +pushd cusf_launcher_crypto +cargo build --release --target x86_64-unknown-linux-gnu +popd +godot --headless --path cusf_launcher/ --export-release "Linux" cusf_launcher.x86_64 +``` Windows: - -`godot --headless --path cusf_launcher/ --export-release "Windows" cusf_launcher.exe` +``` +pushd cusf_launcher_crypto +RUSTFLAGS="-C linker=/usr/bin/x86_64-w64-mingw32-gcc" cargo build --release --target x86_64-pc-windows-gnu +popd +godot --headless --path cusf_launcher/ --export-release "Windows" cusf_launcher.exe +``` Mac: - -`godot --headless --path cusf_launcher/ --export-release "Mac" cusf_launcher.dmg` - +``` +pushd cusf_launcher_crypto +cargo build --release --target x86_64-apple-darwin +popd +godot --headless --path cusf_launcher/ --export-release "Mac" cusf_launcher.dmg` +``` diff --git a/cusf_launcher/CusfLauncherCrypto.gdextension b/cusf_launcher/CusfLauncherCrypto.gdextension new file mode 100644 index 0000000..87e9a10 --- /dev/null +++ b/cusf_launcher/CusfLauncherCrypto.gdextension @@ -0,0 +1,14 @@ +[configuration] +entry_symbol = "gdext_cusf_launcher_crypto_init" +compatibility_minimum = 4.1 +reloadable = true + +[libraries] +linux.debug.x86_64 = "res://../cusf_launcher_crypto/target/x86_64-unknown-linux-gnu/debug/libcusf_launcher_crypto.so" +linux.release.x86_64 = "res://../cusf_launcher_crypto/target/x86_64-unknown-linux-gnu/release/libcusf_launcher_crypto.so" +windows.debug.x86_64 = "res://../cusf_launcher_crypto/target/x86_64-pc-windows-gnu/debug/cusf_launcher_crypto.dll" +windows.release.x86_64 = "res://../cusf_launcher_crypto/target/x86_64-pc-windows-gnu/release/cusf_launcher_crypto.dll" +macos.debug = "res://../cusf_launcher_crypto/target/x86_64-apple-darwin/debug/libcusf_launcher_crypto.dylib" +macos.release = "res://../cusf_launcher_crypto/target/x86_64-apple-darwin/release/libcusf_launcher_crypto.dylib" +macos.debug.arm64 = "res://../cusf_launcher_crypto/target/aarch64-apple-darwin/debug/libcusf_launcher_crypto.dylib" +macos.release.arm64 = "res://../cusf_launcher_crypto/target/aarch64-apple-darwin/release/libcusf_launcher_crypto.dylib" \ No newline at end of file diff --git a/cusf_launcher_crypto/.gitignore b/cusf_launcher_crypto/.gitignore new file mode 100644 index 0000000..c41cc9e --- /dev/null +++ b/cusf_launcher_crypto/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/cusf_launcher_crypto/Cargo.lock b/cusf_launcher_crypto/Cargo.lock new file mode 100644 index 0000000..4a95ac0 --- /dev/null +++ b/cusf_launcher_crypto/Cargo.lock @@ -0,0 +1,282 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "hex-conservative", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cusf_launcher_crypto" +version = "0.1.0" +dependencies = [ + "bitcoin_hashes", + "godot", +] + +[[package]] +name = "gdextension-api" +version = "0.2.0" +source = "git+https://github.com/godot-rust/godot4-prebuilt?branch=releases#6d902e8a6060007f4ab94cd78882247ae2558d96" + +[[package]] +name = "gensym" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "913dce4c5f06c2ea40fc178c06f777ac89fc6b1383e90c254fafb1abe4ba3c82" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "uuid", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "glam" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "779ae4bf7e8421cf91c0b3b64e7e8b40b862fba4d393f59150042de7c4965a94" + +[[package]] +name = "godot" +version = "0.1.3" +source = "git+https://github.com/godot-rust/gdext?branch=master#a0d579900308b87358b646df43c9100b36cc5ba6" +dependencies = [ + "godot-core", + "godot-macros", +] + +[[package]] +name = "godot-bindings" +version = "0.1.3" +source = "git+https://github.com/godot-rust/gdext?branch=master#a0d579900308b87358b646df43c9100b36cc5ba6" +dependencies = [ + "gdextension-api", +] + +[[package]] +name = "godot-cell" +version = "0.1.3" +source = "git+https://github.com/godot-rust/gdext?branch=master#a0d579900308b87358b646df43c9100b36cc5ba6" + +[[package]] +name = "godot-codegen" +version = "0.1.3" +source = "git+https://github.com/godot-rust/gdext?branch=master#a0d579900308b87358b646df43c9100b36cc5ba6" +dependencies = [ + "godot-bindings", + "heck", + "nanoserde", + "proc-macro2", + "quote", + "regex", +] + +[[package]] +name = "godot-core" +version = "0.1.3" +source = "git+https://github.com/godot-rust/gdext?branch=master#a0d579900308b87358b646df43c9100b36cc5ba6" +dependencies = [ + "glam", + "godot-bindings", + "godot-cell", + "godot-codegen", + "godot-ffi", +] + +[[package]] +name = "godot-ffi" +version = "0.1.3" +source = "git+https://github.com/godot-rust/gdext?branch=master#a0d579900308b87358b646df43c9100b36cc5ba6" +dependencies = [ + "gensym", + "godot-bindings", + "godot-codegen", + "libc", + "paste", +] + +[[package]] +name = "godot-macros" +version = "0.1.3" +source = "git+https://github.com/godot-rust/gdext?branch=master#a0d579900308b87358b646df43c9100b36cc5ba6" +dependencies = [ + "godot-bindings", + "proc-macro2", + "quote", + "venial", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "libc" +version = "0.2.161" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "nanoserde" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de9cf844ab1e25a0353525bd74cb889843a6215fa4a0d156fd446f4857a1b99" +dependencies = [ + "nanoserde-derive", +] + +[[package]] +name = "nanoserde-derive" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e943b2c21337b7e3ec6678500687cdc741b7639ad457f234693352075c082204" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "syn" +version = "2.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "uuid" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" +dependencies = [ + "getrandom", +] + +[[package]] +name = "venial" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6816bc32f30bf8dd1b3adb04de8406c7bf187d2f923bd9e4c0b99365d012613f" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/cusf_launcher_crypto/Cargo.toml b/cusf_launcher_crypto/Cargo.toml new file mode 100644 index 0000000..bb7e469 --- /dev/null +++ b/cusf_launcher_crypto/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "cusf_launcher_crypto" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] # Compile this crate to a dynamic C library. + +[dependencies] +bitcoin_hashes = { version = "0.14.0", default-features = false } +godot = { git = "https://github.com/godot-rust/gdext", branch = "master" } \ No newline at end of file diff --git a/cusf_launcher_crypto/src/lib.rs b/cusf_launcher_crypto/src/lib.rs new file mode 100644 index 0000000..4db4991 --- /dev/null +++ b/cusf_launcher_crypto/src/lib.rs @@ -0,0 +1,35 @@ +use bitcoin_hashes::{hmac, ripemd160, sha512, Hash as _, HashEngine}; +use godot::{builtin::PackedByteArray, prelude::{gdextension, godot_api, ExtensionLibrary, GodotClass}}; + +struct MyExtension; + +#[gdextension] +unsafe impl ExtensionLibrary for MyExtension {} + +#[derive(GodotClass)] +#[class(no_init)] +struct Ripemd160; + +#[godot_api] +impl Ripemd160 { + #[func] + fn digest(msg: PackedByteArray) -> PackedByteArray { + let digest = ripemd160::Hash::hash(msg.as_slice()); + digest.to_byte_array().into() + } +} + +#[derive(GodotClass)] +#[class(no_init)] +struct HmacSha512; + +#[godot_api] +impl HmacSha512 { + #[func] + fn hmac(key: PackedByteArray, msg: PackedByteArray) -> PackedByteArray { + let mut engine = hmac::HmacEngine::::new(key.as_slice()); + engine.input(msg.as_slice()); + let hmac = hmac::Hmac::::from_engine(engine); + hmac.to_byte_array().into() + } +} \ No newline at end of file