remove shader directory handling and update documentation
parent
397df566ae
commit
7b92ff3c6b
16
DOCS.md
16
DOCS.md
|
|
@ -24,7 +24,7 @@ Key features:
|
|||
- **Build directives** embedded directly in C++ source files for per-file configuration (dependencies, linking, output, flags)
|
||||
- **Dependency tracking** via `#include` analysis and timestamp checking
|
||||
- **Incremental builds** to recompile only changed files
|
||||
- **Support for shared libraries, tools/executables, and GLSL shaders**
|
||||
- **Support for shared libraries, tools/executables, and asset hooks (e.g., GLSL shaders via dependencies)**
|
||||
- **Simple global configuration** via `config.ini`
|
||||
- **Cross-platform** (Linux, macOS, Windows) with parallel compilation
|
||||
- **No external scripts needed**—everything is in your source files
|
||||
|
|
@ -37,7 +37,7 @@ Lana parses `// build-directive:` comments in your C++ files to handle project-s
|
|||
- V compiler (version 0.3.0 or later)
|
||||
- GCC/G++ (version 7+ recommended)
|
||||
- Standard C++ library
|
||||
- For shaders: Vulkan SDK or shaderc (includes `glslc`)
|
||||
- For shader workflows: Vulkan SDK or shaderc (includes `glslc`)
|
||||
|
||||
### Building Lana
|
||||
|
||||
|
|
@ -74,14 +74,12 @@ project/
|
|||
│ │ └── cli.cpp # Example shared lib (directives at top)
|
||||
│ ├── tools/ # Tool/executable sources
|
||||
│ │ └── example_tool.cpp # Example tool depending on lib/cli
|
||||
│ └── shaders/ # GLSL shaders (.vsh, .fsh)
|
||||
├── include/ # Header files (.h, .hpp)
|
||||
│ └── cli.h # Example header
|
||||
├── build/ # Generated: Object files (*.o), dependencies (*.d)
|
||||
├── bin/ # Generated: Executables and libs
|
||||
│ ├── lib/ # Shared libraries (.so/.dll)
|
||||
│ ├── tools/ # Tool executables
|
||||
│ └── shaders/ # Compiled shaders (.spv)
|
||||
├── config.ini # Global build configuration
|
||||
├── README.md # Project docs (auto-generated with directive examples)
|
||||
└── .gitignore # Ignores build artifacts
|
||||
|
|
@ -89,7 +87,6 @@ project/
|
|||
|
||||
- **Build Directives**: Add `// build-directive:` comments at the top of C++ files for per-file settings (see [Build Directives](#build-directives)).
|
||||
- **Auto-Discovery**: If no directives, Lana treats files as simple tools using global config.
|
||||
- **Shaders**: Place `.vsh` (vertex) and `.fsh` (fragment) files in `src/shaders/`; set `shaders_dir` in config to enable compilation.
|
||||
|
||||
## Commands
|
||||
|
||||
|
|
@ -208,7 +205,6 @@ ldflags =
|
|||
|
||||
# Advanced
|
||||
parallel_compilation = true
|
||||
shaders_dir = bin/shaders # Enable shader compilation
|
||||
dependencies_dir = dependencies
|
||||
```
|
||||
|
||||
|
|
@ -306,7 +302,7 @@ int main() {
|
|||
- **Order**: Directives before `#include` or code.
|
||||
- **Empty Values**: Use `()` for none (e.g., `depends-units()`).
|
||||
- **Global Interaction**: Directives add to `config.ini` settings (e.g., global `-Wall` + per-file `-std=c++20`).
|
||||
- **Shaders**: No directives needed; auto-compiles if `shaders_dir` set.
|
||||
- **Assets**: Use `[dependencies]` hooks for non-C++ steps (e.g., shader compilation).
|
||||
- **Legacy**: Use `[shared_libs]`/`[tools]` in config for manual lists (overrides auto-parsing).
|
||||
|
||||
## Build Process
|
||||
|
|
@ -317,7 +313,7 @@ int main() {
|
|||
4. **Incremental Check**: Recompiles if source/header newer than `.o` or `.d` missing.
|
||||
5. **Compilation**: `g++ -c` each source to `.o` (uses global + per-file flags).
|
||||
6. **Linking**: Builds shared libs/tools per directives (e.g., `g++ -shared` for libs).
|
||||
7. **Shaders** (if enabled): Compiles `.vsh`/`.fsh` to `.spv` with `glslc`.
|
||||
7. **Dependency Hooks**: Executes `[dependencies]` build commands (use for assets like shaders).
|
||||
|
||||
**Example Output** (`lana build -v`):
|
||||
```
|
||||
|
|
@ -400,8 +396,6 @@ libraries =
|
|||
name = main
|
||||
sources = src/main.cpp
|
||||
libraries = cli
|
||||
|
||||
shaders_dir = bin/shaders # Enable shaders
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
|
@ -412,7 +406,7 @@ shaders_dir = bin/shaders # Enable shaders
|
|||
- **"Failed to parse directive"**: Verify syntax (e.g., `unit-name(lib/cli)`); use `-v` for details.
|
||||
- **"Dependency not found"**: Add missing `depends-units()` or build order in directives.
|
||||
- **Linking errors**: Check `link()` for libs; install dev packages (e.g., `sudo apt install libpthread-dev`).
|
||||
- **Shader compilation fails**: Install Vulkan SDK (`glslc`); verify `shaders_dir` in config.
|
||||
- **Asset build fails**: Verify commands in `[dependencies]` hook scripts (e.g., shader toolchain).
|
||||
- **Permission denied**: `chmod +x bin/tools/mytool`.
|
||||
|
||||
### Debugging Tips
|
||||
|
|
|
|||
|
|
@ -116,9 +116,6 @@ pub fn build(mut build_config config.BuildConfig) ! {
|
|||
os.mkdir_all(build_config.bin_dir) or { return error('Failed to create bin directory') }
|
||||
os.mkdir_all('${build_config.bin_dir}/lib') or { return error('Failed to create lib directory') }
|
||||
os.mkdir_all('${build_config.bin_dir}/tools') or { return error('Failed to create tools directory') }
|
||||
if build_config.shaders_dir != '' && build_config.shaders_dir != 'bin/shaders' {
|
||||
os.mkdir_all(build_config.shaders_dir) or { return error('Failed to create shaders directory') }
|
||||
}
|
||||
|
||||
// Auto-discover sources if not specified
|
||||
auto_discover_sources(mut build_config)
|
||||
|
|
@ -168,15 +165,6 @@ pub fn build(mut build_config config.BuildConfig) ! {
|
|||
}
|
||||
}
|
||||
|
||||
// Build shaders if configured and directory exists
|
||||
if build_config.shaders_dir != '' {
|
||||
compile_shaders(build_config) or {
|
||||
if !build_config.verbose {
|
||||
println('Warning: Failed to compile shaders: ${err}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println('Build completed successfully!')
|
||||
return
|
||||
}
|
||||
|
|
@ -450,19 +438,6 @@ pub fn clean(build_config config.BuildConfig) {
|
|||
}
|
||||
}
|
||||
|
||||
// Remove shaders directory if it exists
|
||||
shaders_dir := if build_config.shaders_dir.starts_with('bin/') {
|
||||
os.join_path(build_config.bin_dir, build_config.shaders_dir[4..])
|
||||
} else {
|
||||
build_config.shaders_dir
|
||||
}
|
||||
if os.is_dir(shaders_dir) {
|
||||
os.rmdir_all(shaders_dir) or {
|
||||
println('Warning: Failed to remove ${shaders_dir}: ${err}')
|
||||
}
|
||||
println('Removed ${shaders_dir}')
|
||||
}
|
||||
|
||||
// Remove main executable if it exists (backward compatibility)
|
||||
main_exe := os.join_path(build_config.bin_dir, build_config.project_name)
|
||||
if os.is_file(main_exe) {
|
||||
|
|
@ -698,129 +673,6 @@ fn link_tool(object_files []string, executable string, build_config config.Build
|
|||
}
|
||||
}
|
||||
|
||||
fn compile_shaders(build_config config.BuildConfig) ! {
|
||||
shaders_src_dir := 'src/shaders'
|
||||
if !os.is_dir(shaders_src_dir) {
|
||||
if build_config.verbose {
|
||||
println('No shaders directory found, skipping shader compilation')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
println('Compiling shaders...')
|
||||
|
||||
// Find glslc compiler
|
||||
glslc_path := find_glslc() or {
|
||||
println('Warning: glslc compiler not found, skipping shader compilation')
|
||||
return
|
||||
}
|
||||
|
||||
// Get shaders directory
|
||||
shaders_out_dir := if build_config.shaders_dir.starts_with('bin/') {
|
||||
os.join_path(build_config.bin_dir, build_config.shaders_dir[4..])
|
||||
} else {
|
||||
build_config.shaders_dir
|
||||
}
|
||||
|
||||
os.mkdir_all(shaders_out_dir) or { return error('Failed to create shaders output directory') }
|
||||
|
||||
// List all shader files
|
||||
shader_files := os.ls(shaders_src_dir) or { return error('Failed to list shaders directory') }
|
||||
mut shader_count := 0
|
||||
mut success_count := 0
|
||||
|
||||
// Compile vertex shaders (.vsh)
|
||||
for shader in shader_files {
|
||||
if !shader.ends_with('.vsh') {
|
||||
continue
|
||||
}
|
||||
|
||||
shader_count++
|
||||
src_path := os.join_path(shaders_src_dir, shader)
|
||||
output_name := shader.replace('.vsh', '.vsh.spv')
|
||||
output_path := os.join_path(shaders_out_dir, output_name)
|
||||
|
||||
cmd := '${glslc_path} -o ${output_path} -fshader-stage=vertex ${src_path}'
|
||||
if build_config.debug || build_config.verbose {
|
||||
println('Compiling vertex shader: ${shader}')
|
||||
}
|
||||
|
||||
if build_config.verbose {
|
||||
println('Shader compile command: ${cmd}')
|
||||
}
|
||||
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
println('Error compiling ${shader}: ${res.output}')
|
||||
} else {
|
||||
success_count++
|
||||
if build_config.verbose {
|
||||
println('Compiled: ${shader} -> ${output_path}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compile fragment shaders (.fsh)
|
||||
for shader in shader_files {
|
||||
if !shader.ends_with('.fsh') {
|
||||
continue
|
||||
}
|
||||
|
||||
shader_count++
|
||||
src_path := os.join_path(shaders_src_dir, shader)
|
||||
output_name := shader.replace('.fsh', '.fsh.spv')
|
||||
output_path := os.join_path(shaders_out_dir, output_name)
|
||||
|
||||
cmd := '${glslc_path} -o ${output_path} -fshader-stage=fragment ${src_path}'
|
||||
if build_config.debug || build_config.verbose {
|
||||
println('Compiling fragment shader: ${shader}')
|
||||
}
|
||||
|
||||
if build_config.verbose {
|
||||
println('Shader compile command: ${cmd}')
|
||||
}
|
||||
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
println('Error compiling ${shader}: ${res.output}')
|
||||
} else {
|
||||
success_count++
|
||||
if build_config.verbose {
|
||||
println('Compiled: ${shader} -> ${output_path}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if shader_count == 0 {
|
||||
println('No shaders found to compile')
|
||||
} else {
|
||||
println('Shader compilation complete: ${success_count}/${shader_count} successful')
|
||||
}
|
||||
}
|
||||
|
||||
fn find_glslc() !string {
|
||||
// Check common locations
|
||||
paths := [
|
||||
'/usr/bin/glslc',
|
||||
'/usr/local/bin/glslc',
|
||||
'/opt/homebrew/bin/glslc' // macOS
|
||||
]
|
||||
|
||||
for path in paths {
|
||||
if os.is_file(path) {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
// Try PATH using os.which
|
||||
glslc_path := os.find_abs_path_of_executable('glslc') or { panic(err) }
|
||||
if glslc_path != '' {
|
||||
return glslc_path
|
||||
}
|
||||
|
||||
return error('glslc not found. Install Vulkan SDK or shaderc')
|
||||
}
|
||||
|
||||
fn get_object_file(source_file string, object_dir string) string {
|
||||
// Compute object file path by preserving the path under src/ and placing it under object_dir
|
||||
// e.g., src/lib/file.cpp -> <object_dir>/lib/file.o
|
||||
|
|
|
|||
|
|
@ -78,7 +78,6 @@ __global:
|
|||
// New fields for shared library support
|
||||
shared_libs []SharedLibConfig
|
||||
tools []ToolConfig
|
||||
shaders_dir string = 'bin/shaders' // for shader compilation
|
||||
dependencies_dir string = 'dependencies' // external dependencies
|
||||
parallel_compilation bool = true // enable parallel builds
|
||||
dependencies []Dependency
|
||||
|
|
@ -394,7 +393,6 @@ pub fn parse_config_file(filename string) !BuildConfig {
|
|||
flags := value.split(' ')
|
||||
for flag in flags { build_config.ldflags << flag.trim_space() }
|
||||
}
|
||||
'shaders_dir' { build_config.shaders_dir = value }
|
||||
'dependencies_dir' { build_config.dependencies_dir = value }
|
||||
else {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,12 +48,10 @@ pub fn show_help() {
|
|||
println(' src/ - Source files (.cpp, .cc, .cxx)')
|
||||
println(' lib/ - Shared library sources')
|
||||
println(' tools/ - Tool/executable sources')
|
||||
println(' shaders/ - GLSL shader files (.vsh, .fsh)')
|
||||
println(' include/ - Header files (.h, .hpp)')
|
||||
println(' build/ - Object files and intermediates')
|
||||
println(' bin/ - Output')
|
||||
println(' lib/ - Shared libraries (.so/.dll)')
|
||||
println(' tools/ - Executables')
|
||||
println(' shaders/ - Compiled shaders (.spv)')
|
||||
println(' config.ini - Build configuration')
|
||||
}
|
||||
|
|
@ -12,13 +12,11 @@ pub fn init_project(project_name string) {
|
|||
'src/lib/net',
|
||||
'src/lib/game',
|
||||
'src/tools',
|
||||
'src/shaders',
|
||||
'include',
|
||||
'build',
|
||||
'bin',
|
||||
'bin/lib',
|
||||
'bin/tools',
|
||||
'bin/shaders'
|
||||
'bin/tools'
|
||||
]
|
||||
for dir in dirs {
|
||||
full_path := os.join_path(project_name, dir)
|
||||
|
|
@ -77,16 +75,6 @@ int main() {
|
|||
'
|
||||
os.write_file(os.join_path(project_name, 'src/tools', 'example_tool.cpp'), tool_content) or { }
|
||||
|
||||
// Create example shader
|
||||
vertex_shader := r'
|
||||
#version 450
|
||||
layout(location = 0) in vec3 position;
|
||||
void main() {
|
||||
gl_Position = vec4(position, 1.0);
|
||||
}
|
||||
'
|
||||
os.write_file(os.join_path(project_name, 'src/shaders', 'basic.vsh'), vertex_shader) or { }
|
||||
|
||||
// Create .gitignore
|
||||
gitignore_content := r'
|
||||
# Build files
|
||||
|
|
@ -145,8 +133,6 @@ ldflags =
|
|||
# These are for legacy support or manual configuration
|
||||
# Most tools should use build directives in source files
|
||||
|
||||
# Uncomment for shader support
|
||||
# shaders_dir = bin/shaders
|
||||
'
|
||||
os.write_file(os.join_path(project_name, 'config.ini'), config_content) or { }
|
||||
|
||||
|
|
@ -182,13 +168,11 @@ lana clean
|
|||
- `src/` - Source files (.cpp, .cc, .cxx)
|
||||
- `lib/` - Shared library sources
|
||||
- `tools/` - Tool/executable sources
|
||||
- `shaders/` - GLSL shader files (.vsh, .fsh)
|
||||
- `include/` - Header files (.h, .hpp)
|
||||
- `build/` - Object files and intermediate build files
|
||||
- `bin/` - Executable output
|
||||
- `lib/` - Shared libraries (.so/.dll)
|
||||
- `tools/` - Tool executables
|
||||
- `shaders/` - Compiled shaders (.spv)
|
||||
- `config.ini` - Build configuration
|
||||
|
||||
## Build Directives
|
||||
|
|
@ -277,12 +261,6 @@ sources = src/tools/example_tool.cpp
|
|||
libraries = cli
|
||||
```
|
||||
|
||||
### Shader Support
|
||||
```ini
|
||||
# Uncomment to enable shader compilation
|
||||
shaders_dir = bin/shaders
|
||||
```
|
||||
|
||||
## Command Line Options
|
||||
```bash
|
||||
lana build [options]
|
||||
|
|
@ -306,7 +284,7 @@ lana build [options]
|
|||
2. **Build dependency graph** based on unit dependencies
|
||||
3. **Compile source files** to object files
|
||||
4. **Link libraries and executables** according to directives
|
||||
5. **Compile shaders** if configured
|
||||
5. **Execute dependency hooks** declared under `[dependencies]` (ideal for assets like shaders)
|
||||
|
||||
The build system automatically handles:
|
||||
- Dependency resolution and build ordering
|
||||
|
|
@ -412,5 +390,5 @@ namespace lana {
|
|||
println('Configuration:')
|
||||
println(' Edit config.ini for global build settings')
|
||||
println(' Add your C++ source files to src/lib/ and src/tools/')
|
||||
println(' Add GLSL shaders to src/shaders/ (.vsh, .fsh)')
|
||||
println(' Use [dependencies] entries for extra asset steps (e.g., shader compilation)')
|
||||
}
|
||||
Loading…
Reference in New Issue