Skip to content

Commit

Permalink
chore(scirpts): make scripts prettier and less noisy
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Dec 31, 2024
1 parent 34c51a8 commit 2d2c036
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 24 deletions.
58 changes: 52 additions & 6 deletions Scripts/bindgen.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
#!/bin/bash

castffi extract --config Bindings/config-extract-linux.json
castffi extract --config Bindings/config-extract-macos.json
castffi extract --config Bindings/config-extract-windows.json
# Print colorful status messages
print_status() {
echo -e "\033[1;34m$1\033[0m"
}

# Merge platform abstract syntax tree .json files into a cross-platform abstract syntax tree.
castffi merge --inputDirectoryPath Bindings/ast --outputFilePath Bindings/ast/cross-platform.json
print_error() {
echo -e "\033[1;31m$1\033[0m"
}

./c2cs/artifacts/bin/C2CS.Tool/release/C2CS.Tool generate --config Bindings/config-generate-cs.json
print_success() {
echo -e "\033[1;32m$1\033[0m"
}

print_status "Extracting platform-specific bindings..."

# Extract bindings for each platform
castffi extract --config Bindings/config-extract-linux.json > /dev/null 2>&1
if [ $? -ne 0 ]; then
print_error "Failed to extract Linux bindings"
exit 1
fi

castffi extract --config Bindings/config-extract-macos.json > /dev/null 2>&1
if [ $? -ne 0 ]; then
print_error "Failed to extract macOS bindings"
exit 1
fi

castffi extract --config Bindings/config-extract-windows.json > /dev/null 2>&1
if [ $? -ne 0 ]; then
print_error "Failed to extract Windows bindings"
exit 1
fi

print_status "Merging platform bindings..."

# Merge platform abstract syntax tree .json files
castffi merge --inputDirectoryPath Bindings/ast --outputFilePath Bindings/ast/cross-platform.json > /dev/null 2>&1
if [ $? -ne 0 ]; then
print_error "Failed to merge platform bindings"
exit 1
fi

print_status "Generating C# bindings..."

# Generate C# bindings
./c2cs/artifacts/bin/C2CS.Tool/release/C2CS.Tool generate --config Bindings/config-generate-cs.json > /dev/null 2>&1
if [ $? -ne 0 ]; then
print_error "Failed to generate C# bindings"
exit 1
fi

print_success "✨ Bindings generation complete!"
print_status "Done! 🎮"
63 changes: 50 additions & 13 deletions Scripts/libgen.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
#!/bin/bash
# Define the targets

# Print colorful status messages
print_status() {
echo -e "\033[1;34m$1\033[0m"
}

print_error() {
echo -e "\033[1;31m$1\033[0m"
}

print_success() {
echo -e "\033[1;32m$1\033[0m"
}

# Define the targets
targets=("x86_64-unknown-linux-gnu" "x86_64-apple-darwin" "aarch64-apple-darwin" "x86_64-pc-windows-gnu" "aarch64-apple-ios")

cd ./Bindings/dojo.c

# Determine build type
if [[ "$1" == "debug" ]]; then
build="debug"
build="debug"
print_status "Building in debug mode..."
else
build="release"
build="release"
print_status "Building in release mode..."
fi

print_status "Setting up linkers..."

# Configure linkers
# Linux linker
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc
# Windows linker
Expand All @@ -20,33 +39,51 @@ export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="$(ls /Applications/Unity/Hub/Editor/*/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/*/bin/armv7a-linux-androideabi*-clang | sort | tail -n 1)"
# Arm64 android linker
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$(ls /Applications/Unity/Hub/Editor/*/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/*/bin/aarch64-linux-android*-clang | sort | tail -n 1)"

print_status "Building targets..."

# Loop over the targets
for target in "${targets[@]}"; do
rm -rf "../../Assets/Dojo/Libraries/$target"

# Build binary for the target
if [[ "$build" == "release" ]]; then
cargo build --release --target "$target"
else
cargo build --target "$target"
fi
print_status "Building for $target..."
rm -rf "../../Assets/Dojo/Libraries/$target"

# Build binary for the target
if [[ "$build" == "release" ]]; then
cargo build --release --target "$target" > /dev/null 2>&1
else
cargo build --target "$target" > /dev/null 2>&1
fi

if [ $? -ne 0 ]; then
print_error "Failed to build for $target"
exit 1
fi
done

print_status "Copying binaries to Unity project..."

# Windows
print_status "Setting up Windows plugins..."
mkdir -p "../../Assets/Dojo/Plugins/Windows"
cp -f "target/x86_64-pc-windows-gnu/$build/dojo_c.dll" "../../Assets/Dojo/Plugins/Windows/libdojo_c.dll"

# Linux
print_status "Setting up Linux plugins..."
mkdir -p "../../Assets/Dojo/Plugins/Linux"
cp -f "target/x86_64-unknown-linux-gnu/$build/libdojo_c.so" "../../Assets/Dojo/Plugins/Linux/libdojo_c.so"

# macOS
print_status "Setting up macOS plugins..."
mkdir -p "../../Assets/Dojo/Plugins/macOS"
# we need to bundle the x86_64 and arm64 libraries into a single fat binary
lipo -create -output "../../Assets/Dojo/Plugins/macOS/libdojo_c.bundle" \
"target/x86_64-apple-darwin/$build/libdojo_c.dylib" \
"target/aarch64-apple-darwin/$build/libdojo_c.dylib"
"target/x86_64-apple-darwin/$build/libdojo_c.dylib" \
"target/aarch64-apple-darwin/$build/libdojo_c.dylib"

# iOS
print_status "Setting up iOS plugins..."
mkdir -p "../../Assets/Dojo/Plugins/iOS"
cp -f "target/aarch64-apple-ios/$build/libdojo_c.a" "../../Assets/Dojo/Plugins/iOS/libdojo_c.a"

print_success "✨ Build complete!"
print_status "Done! 🎮"
39 changes: 34 additions & 5 deletions Scripts/wasmgen.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
# Get rid of old wasm package
#!/bin/bash

# Print colorful status messages
print_status() {
echo -e "\033[1;34m$1\033[0m"
}

print_error() {
echo -e "\033[1;31m$1\033[0m"
}

print_success() {
echo -e "\033[1;32m$1\033[0m"
}

print_status "Cleaning old WASM package..."
rm -rf ./Assets/WebGLTemplates/Dojo/TemplateData/dojo.js/*
if [ $? -ne 0 ]; then
print_error "Failed to clean old WASM package"
exit 1
fi

# Build the wasm package
print_status "Building WASM package..."
cd ./Bindings/dojo.c
./scripts/build_wasm.sh > /dev/null 2>&1
if [ $? -ne 0 ]; then
print_error "Failed to build WASM package"
exit 1
fi

./scripts/build_wasm.sh
print_status "Copying WASM package to WebGL template..."
cp ./pkg/* ../../Assets/WebGLTemplates/Dojo/TemplateData/dojo.js
if [ $? -ne 0 ]; then
print_error "Failed to copy WASM package"
exit 1
fi

# Copy the wasm package to the webgl template
cp ./pkg/* ../../Assets/WebGLTemplates/Dojo/TemplateData/dojo.js
print_success "✨ WASM generation complete!"
print_status "Done! 🎮"

0 comments on commit 2d2c036

Please sign in to comment.