UBuilder follows a modular, extensible architecture designed for cross-platform compatibility and runtime flexibility.
┌─────────────────────────────────────────────────────────────┐
│ UBuilder Core │
├─────────────────────────────────────────────────────────────┤
│ CLI Interface │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐│
│ │ Argument Parser │ │ Configuration │ │ Output Manager ││
│ │ │ │ Validator │ │ ││
│ └─────────────────┘ └─────────────────┘ └─────────────────┘│
├─────────────────────────────────────────────────────────────┤
│ Build Pipeline │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐│
│ │ Project Scanner │ │ Runtime Builder │ │ Executable ││
│ │ │ │ Registry │ │ Generator ││
│ └─────────────────┘ └─────────────────┘ └─────────────────┘│
├─────────────────────────────────────────────────────────────┤
│ Runtime Embedder System │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐│
│ │ Binary Detector │ │ Runtime Embedder│ │ Extraction ││
│ │ │ │ │ │ Manager ││
│ └─────────────────┘ └─────────────────┘ └─────────────────┘│
├─────────────────────────────────────────────────────────────┤
│ Runtime-Specific Builders │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐│
│ │ PHP Builder │ │ Python Builder │ │ Node.js Builder ││
│ │ │ │ │ │ ││
│ └─────────────────┘ └─────────────────┘ └─────────────────┘│
└─────────────────────────────────────────────────────────────┘
Location: src/main.c
Responsibility: Command-line argument parsing and user interaction
- Argument Parser: Processes command-line options
- Configuration Validator: Validates project structure and runtime availability
- Output Manager: Handles user feedback and error reporting
Location: src/core/ubuilder.{h,c}
Responsibility: Central orchestration and cross-platform abstractions
- Build Pipeline Controller: Manages the overall build process
- Platform Abstraction: Handles OS-specific operations
- Error Management: Centralized error handling and reporting
Location: src/runtimes/runtime_builder.{h,c}
Responsibility: Extensible runtime support framework
- Builder Registry: Manages available runtime builders
- Builder Interface: Standardized API for runtime-specific operations
- Validation Framework: Project validation for each runtime
Location: src/runtimes/runtime_embedder.{h,c}
Responsibility: True runtime embedding capabilities
- Binary Detection: Automatically finds system runtime binaries
- Binary Embedding: Embeds complete runtime interpreters
- Extraction System: Runtime extraction and execution
Location: src/runtimes/{php,python,nodejs}_builder.c
Responsibility: Language-specific build logic
Each builder implements:
- Project validation
- Runtime embedding
- Application packaging
- Launcher generation
graph TD
A[User Input] --> B[Argument Parsing]
B --> C[Configuration Validation]
C --> D[Project Discovery]
D --> E[Runtime Detection]
E --> F[Builder Selection]
F --> G[Project Validation]
G --> H[Executable Template Copy]
H --> I[Runtime Embedding]
I --> J[Application Embedding]
J --> K[Launcher Generation]
K --> L[Final Executable]
- Argument Parsing: Process CLI arguments and validate required parameters
- Configuration Loading: Load project configuration and validate settings
- Environment Check: Verify build environment and dependencies
- Project Scanning: Analyze project structure and detect entry points
- Runtime Detection: Locate system runtime binaries and check versions
- Builder Selection: Choose appropriate runtime builder
- Project Validation: Runtime-specific project structure validation
- Dependency Check: Verify all required files are present
- Compatibility Check: Ensure runtime and project compatibility
- Template Creation: Copy UBuilder executable as base template
- Runtime Embedding: Embed complete runtime interpreter
- Application Packaging: Bundle all project files
- Metadata Generation: Create execution metadata
- Launcher Integration: Embed runtime-specific launcher
- Marker Insertion: Add embedded data markers
- Permission Setting: Set executable permissions
- Verification: Validate final executable
graph TD
A[Executable Started] --> B[Self-Detection]
B --> C[Marker Search]
C --> D[Runtime Type Detection]
D --> E[Temp Directory Creation]
E --> F[Runtime Binary Extraction]
F --> G[Application Files Extraction]
G --> H[Working Directory Setup]
H --> I[Runtime Execution]
I --> J[Cleanup]
J --> K[Exit]
- Executable Analysis: Check if current process is an embedded UBuilder app
- Marker Search: Look for embedded data markers in executable
- Format Detection: Distinguish between true embedding and launcher formats
- Temp Directory Creation: Create isolated execution environment
- Runtime Extraction: Extract embedded interpreter binary
- Application Extraction: Extract all project files
- Permission Setup: Set proper file permissions
- Working Directory: Change to extracted application directory
- Runtime Invocation: Execute embedded interpreter with application
- Argument Forwarding: Pass command-line arguments to application
- Temp File Removal: Clean up extracted files
- Resource Release: Free allocated memory and handles
- Exit Code Forwarding: Return application exit code
- Create Builder Implementation:
// src/runtimes/mylang_builder.c
static ub_result_t mylang_validate_project(const char* project_dir) {
// Validation logic
}
static ub_result_t mylang_embed_runtime(FILE* output_file) {
// Runtime embedding logic
}
const ub_runtime_builder_t mylang_builder = {
.runtime_type = UB_RUNTIME_MYLANG,
.name = "MyLang",
.description = "MyLang runtime builder",
.validate_project = mylang_validate_project,
.embed_runtime = mylang_embed_runtime,
// ... other functions
};- Register in Builder Registry:
// src/runtimes/runtime_builder.c
static const ub_runtime_builder_t* g_builders[] = {
&python_builder,
&php_builder,
&nodejs_builder,
&mylang_builder, // Add new builder
NULL
};- Add Runtime Type:
// src/core/ubuilder.h
typedef enum {
UB_RUNTIME_UNKNOWN = -1,
UB_RUNTIME_PYTHON = 0,
UB_RUNTIME_PHP = 1,
UB_RUNTIME_NODEJS = 2,
UB_RUNTIME_MYLANG = 3, // Add new type
} ub_runtime_type_t;The architecture supports custom build hooks for advanced scenarios:
typedef struct {
ub_result_t (*pre_build_hook)(const ub_config_t* config);
ub_result_t (*post_build_hook)(const char* output_path);
ub_result_t (*pre_runtime_embed_hook)(FILE* output_file);
ub_result_t (*post_runtime_embed_hook)(FILE* output_file);
} ub_build_hooks_t;- Small Projects (<10 files): O(n) where n = number of files
- Large Projects (>100 files): O(n log n) due to directory traversal
- Runtime Embedding: O(r) where r = runtime binary size
- Build Process: ~10MB base + runtime size
- Runtime Execution: ~5MB overhead + application memory
- PHP: ~100:1 compression ratio (54KB → 6MB includes full PHP)
- Python: ~20:1 compression ratio (application → embedded size)
- Node.js: ~1:1 ratio due to large Node.js binary
- Binary Verification: Checksums of embedded runtime binaries
- Path Validation: Prevent directory traversal attacks
- Permission Isolation: Temporary files created with minimal permissions
- Isolated Execution: Extracted files in temporary, restricted directories
- Cleanup Guarantee: Automatic cleanup even on abnormal termination
- Permission Drop: No elevated privileges during execution
- Code Signing: Support for executable signing (future)
- Integrity Checks: Embedded checksums for tamper detection
- Reproducible Builds: Deterministic build process
- Compression System: Runtime and application compression
- Plugin Architecture: Dynamic runtime plugin loading
- Resource Bundling: Advanced asset management
- Cross-Compilation: Build for different target platforms
- Package Management: Integration with language package managers