Quick Start Guide¶
This tutorial demonstrates Blade usage through a "Hello World" example, providing hands-on experience with the build system.
Workspace Setup¶
Create a new workspace directory:
Creating the say Library¶
Header File Definition¶
Create say.h with the following content:
#pragma once
#include <string>
// Output a message to standard output
void Say(const std::string& msg);
Implementation File¶
Create say.cpp with the implementation:
#include "say.h"
#include <iostream>
void Say(const std::string& msg) {
std::cout << msg << "!\n";
}
BUILD File Configuration¶
Define the library in a BUILD file:
Key Concepts:
- cc_library: Declares a C/C++ library target
- hdrs: Public interface header files
- srcs: Implementation source files (including private headers)
Creating the hello Library¶
Header File Definition¶
Create hello.h:
Implementation File¶
Create hello.cpp:
BUILD File Configuration¶
Extend the BUILD file with the hello library:
Dependency Management:
- deps: Specifies library dependencies
- : prefix: Indicates target within the same BUILD file
- Transitive dependencies: Blade automatically handles dependency propagation
Creating the hello-world Executable¶
Source File¶
Create hello-world.c:
BUILD File Extension¶
Add the executable target to the BUILD file:
Dependency Strategy:
- cc_binary: Creates an executable target
- Direct dependencies only: Only specify immediate dependencies
- Transitive handling: Blade automatically includes indirect dependencies
Build and Execution¶
Build Process¶
Program Execution¶
$ blade run :hello-world
Blade(info): Building...
Blade(info): Build success.
Blade(info): Run['~/quick-start/build_release/hello-world']
Hello, World!
More Examples¶
For complete, runnable examples covering C/C++, Python, Java, Proto, Thrift
and other language features, see the dedicated regression workspace
blade-build/blade-test. Each
subdirectory under suites/ is a standalone project that you can build and
test with blade test //..., and also serves as the end-to-end smoke test
source for blade itself.
Learning Outcomes: - Understanding Blade's declarative build configuration - Mastering dependency management principles - Learning incremental build optimization strategies - Gaining practical experience with C/C++ project structure