-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.sh
executable file
·223 lines (184 loc) · 4.86 KB
/
project.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Error handling
set -e
trap 'handle_error $? $LINENO' ERR
handle_error() {
local exit_code=$1
local line_number=$2
echo -e "${RED}Error: Command failed at line $line_number with exit code $exit_code${NC}"
}
# Set environment variables for macOS
setup_macos_env() {
if [[ "$(uname)" == "Darwin" ]]; then
echo -e "${YELLOW}Setting up macOS environment...${NC}"
export MACOSX_DEPLOYMENT_TARGET=11.0
export SDKROOT=$(xcrun --show-sdk-path)
fi
}
# Clean project
clean_project() {
echo -e "${YELLOW}Cleaning project...${NC}"
if [ -d "target" ]; then
# Use sudo only if necessary
if ! rm -rf target/ 2>/dev/null; then
echo -e "${YELLOW}Requesting permission to remove target directory...${NC}"
sudo rm -rf target/
fi
fi
if [ -d "examples" ]; then
rm -rf examples/
fi
# Use cargo clean without removing target directory
cargo clean
}
# Create project structure
create_structure() {
echo -e "${YELLOW}Creating project structure...${NC}"
# Create directories with proper permissions
mkdir -p src/{core,graphics,input,utils,platform,math}
mkdir -p examples/basic
mkdir -p tests
# Set proper permissions
chmod -R 755 src examples tests
# Create source files
create_source_files
# Create example files
create_example_files
# Create test files
create_test_files
}
# Create source files
create_source_files() {
echo -e "${YELLOW}Creating source files...${NC}"
# Create lib.rs
cat > src/lib.rs << 'EOF'
pub mod core;
pub mod graphics;
pub mod input;
pub mod utils;
pub mod platform;
pub mod math;
pub use graphics::*;
pub use input::*;
pub use platform::*;
pub use math::*;
EOF
# Set proper permissions for created files
chmod 644 src/lib.rs
}
# Create example files
create_example_files() {
echo -e "${YELLOW}Creating example files...${NC}"
# Ensure the directory exists
mkdir -p examples/basic
# Create basic window example
cat > examples/basic/window.rs << 'EOF'
use winit::event_loop::EventLoop;
use nyanko_engine::platform::PlatformWindow;
fn main() {
let event_loop = EventLoop::new();
let window = winit::window::Window::new(&event_loop).unwrap();
let _platform_window = PlatformWindow::new(window);
println!("Basic window example initialized");
}
EOF
# Create basic graphics example
cat > examples/basic/graphics.rs << 'EOF'
use nyanko_engine::graphics::{Renderer, RendererConfig};
use nyanko_engine::platform::PlatformWindow;
use winit::event_loop::EventLoop;
fn main() {
let event_loop = EventLoop::new();
let window = winit::window::Window::new(&event_loop).unwrap();
let platform_window = PlatformWindow::new(window);
let config = RendererConfig::default();
let _renderer = Renderer::new(platform_window, config);
println!("Basic graphics example initialized");
}
EOF
# Create basic input example
cat > examples/basic/input.rs << 'EOF'
use nyanko_engine::input::PlatformInput;
fn main() {
let mut input = PlatformInput::new();
input.update();
println!("Basic input example initialized");
}
EOF
# Set proper permissions
chmod 644 examples/basic/*.rs
}
# Create test files
create_test_files() {
echo -e "${YELLOW}Creating test files...${NC}"
# Create basic tests
cat > tests/lib.rs << 'EOF'
use nyanko_engine::*;
#[test]
fn test_basic() {
assert!(true);
}
EOF
# Set proper permissions
chmod 644 tests/lib.rs
}
# Run tests
run_tests() {
echo -e "${YELLOW}Running tests...${NC}"
RUST_BACKTRACE=1 cargo test --all-features -- --nocapture
}
# Run examples
run_examples() {
echo -e "${YELLOW}Running examples...${NC}"
for example in examples/basic/*; do
if [ -f "$example" ]; then
echo -e "${YELLOW}Running example: $(basename "$example")${NC}"
RUST_BACKTRACE=1 cargo run --example "$(basename "$example" .rs)"
fi
done
}
# Setup project
setup_project() {
echo -e "${YELLOW}Setting up project...${NC}"
clean_project
create_structure
cargo build
}
# Main execution
main() {
# Ensure script has execute permissions
if [ ! -x "$0" ]; then
chmod +x "$0"
fi
case "$1" in
"setup")
setup_macos_env
setup_project
;;
"test")
setup_macos_env
run_tests
;;
"examples")
setup_macos_env
run_examples
;;
"all" | "")
setup_macos_env
setup_project
run_tests
run_examples
;;
*)
echo "Usage: $0 [setup|test|examples|all]"
exit 1
;;
esac
}
# Run main function with arguments
main "$@"