Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cargo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "splashkit"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "0.2"

[build-dependencies]
cc = "1.0"

[lib]
name = "splashkit"
crate-type = ["rlib"]

links = "SplashKit"
35 changes: 35 additions & 0 deletions cargo/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::env;
use std::path::PathBuf;

fn main() {
let home = env::var("HOME").unwrap_or_else(|_| String::from("/"));
let username = env::var("USER").unwrap_or_else(|_| String::from(""));

// Define search paths based on OS
let search_paths = match env::consts::OS {
"macos" => vec![
PathBuf::from("/usr/local/lib"),
PathBuf::from(&home).join(".splashkit/lib/macos"),
],
"linux" => vec![
PathBuf::from("/usr/local/lib"),
PathBuf::from(&home).join(".splashkit/lib/linux"),
],
"windows" => vec![
PathBuf::from(env::var("SYSTEMROOT").unwrap_or(String::from("C:/Windows"))).join("System32"),
PathBuf::from(format!("C:/msys64/home/{}", username)).join(".splashkit/lib/win64"),
],
_ => panic!("Unsupported operating system")
};

// Add all search paths
for path in search_paths {
println!("cargo:rustc-link-search=native={}", path.display());
}

// Link against SplashKit
println!("cargo:rustc-link-lib=dylib=SplashKit");

// Rebuild if this build script changes
println!("cargo:rerun-if-changed=build.rs");
}
36 changes: 36 additions & 0 deletions cargo/cargo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

APP_PATH=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+1] != "") { if (patharr[idx] != "/") {printf("%s/", patharr[idx]); idx++ }} }'`
APP_PATH=`cd "$APP_PATH"; pwd`

SKM_PATH=`cd "$APP_PATH/.."; pwd`

source "${SKM_PATH}/tools/set_sk_env_vars.sh"

# Set Rust library path
RUST_LIB="${HOME}/.splashkit/cargo"

# Check if Cargo.toml exists
if [ -f "Cargo.toml" ]; then
sed -i "s|splashkit.*=.*{.*path.*=.*\".*\".*}|splashkit = { path = \"${RUST_LIB}\" }|" Cargo.toml

# If splashkit wasn't found, add it
if ! grep -q "splashkit.*=.*{.*path.*=.*\".*\".*}" Cargo.toml; then
# Add empty line if needed
if [ -s Cargo.toml ]; then
echo "" >> Cargo.toml
fi
echo "splashkit = { path = \"${RUST_LIB}\" }" >> Cargo.toml
fi
fi

if [ "$SK_OS" = "win64" ]; then
PATH="$DYLIB_PATH:$PATH" cargo $*
elif [ "$SK_OS" = "macos" ]; then
DYLD_LIBRARY_PATH="$DYLIB_PATH" cargo $*
elif [ "$SK_OS" = "linux" ]; then
LD_LIBRARY_PATH="$DYLIB_PATH:$LD_LIBRARY_PATH" cargo $*
else
echo "Unable to detect operating system..."
exit 1
fi
19 changes: 19 additions & 0 deletions cargo/help.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

APP_PATH=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+1] != "") { if (patharr[idx] != "/") {printf("%s/", patharr[idx]); idx++ }} }'`
APP_PATH=`cd "$APP_PATH"; pwd`

SKM_PATH=`cd "$APP_PATH/.."; pwd`

source "${SKM_PATH}/tools/set_sk_env_vars.sh"

if [ "$SK_OS" = "win64" ]; then
PATH="$DYLIB_PATH:$PATH" cargo $*
elif [ "$SK_OS" = "macos" ]; then
DYLD_LIBRARY_PATH="$DYLIB_PATH" cargo $*
elif [ "$SK_OS" = "linux" ]; then
LD_LIBRARY_PATH="$DYLIB_PATH:$LD_LIBRARY_PATH" cargo $*
else
echo "Unable to detect operating system..."
exit 1
fi
Loading