mirror of
https://github.com/Zenithsiz/zbuild.git
synced 2026-02-03 22:23:53 +00:00
Updated example and created it on examples/.
This commit is contained in:
parent
4c0e3cfe18
commit
34b2abc732
73
README.md
73
README.md
@ -4,84 +4,21 @@ zbuild is a modern makefile-like build automation tool.
|
||||
|
||||
# Guide
|
||||
|
||||
See the [Guide](./GUIDE.md) for a proper introduction to zbuild.
|
||||
|
||||
# Example
|
||||
|
||||
Zbuild uses a yaml file to specify all rules. It will look for for the nearest `zbuild.yaml` file in the current or parent directories.
|
||||
|
||||
If you have a project in C, with the following directory structure, the zbuild specified can build your project.
|
||||
See the [Guide](./GUIDE.md) for a proper introduction to zbuild.
|
||||
|
||||
```
|
||||
my_proj/
|
||||
build/
|
||||
a.o
|
||||
b.o
|
||||
my_proj.out
|
||||
src/
|
||||
a.c
|
||||
b.c
|
||||
```
|
||||
# Examples
|
||||
|
||||
`zbuild.yaml`:
|
||||
See the `examples/` directory for examples.
|
||||
|
||||
```yaml
|
||||
# Global aliases
|
||||
# These are aliases that may be used in the whole manifest.
|
||||
# You can reference them by using `$(<name>)` at any point.
|
||||
alias:
|
||||
build_dir: build
|
||||
src_dir: src
|
||||
|
||||
# Default targets
|
||||
# These are the targets (i.e. files / rules) that will be built
|
||||
# when no command line arguments are given.
|
||||
default:
|
||||
- $(build_dir)/my_proj.out
|
||||
|
||||
# Rules
|
||||
# zbuild will examine these to figure out how to build any target
|
||||
rules:
|
||||
# Each rule has a unique name, used only for it's identification
|
||||
compile_o:
|
||||
# Rule aliases
|
||||
# Rules may contain scoped aliases, specific to them.
|
||||
alias:
|
||||
# `^(...)` specifies a pattern to match, every other instance of it will be replaced in the rest of the rule.
|
||||
# Patterns are simple string replacements currently.
|
||||
# You may also only have a single pattern per rule currently.
|
||||
output: $(build_dir)/^(name).o
|
||||
input: $(src_dir)/^(name).c
|
||||
|
||||
# Output items
|
||||
# These are the items that your rule outputs.considered.
|
||||
out: [$(output)]
|
||||
|
||||
# Dependencies
|
||||
# These are the items that your rule requires.
|
||||
deps: [$(input)]
|
||||
|
||||
# Execution
|
||||
#
|
||||
# Specifies an array of commands to execute to build this rule. Each command is an array of arguments. It will not be passed to a shell, but instead be executed as-is
|
||||
exec:
|
||||
- [gcc, $(input), -c, -o, $(output)]
|
||||
|
||||
compile_out:
|
||||
out: [$(build_dir)/my_proj.out]
|
||||
deps: [$(build_dir)/a.o, $(build_dir)/b.o]
|
||||
|
||||
exec:
|
||||
- [gcc, $(build_dir)/a.o, $(build_dir)/b.o, -o, $(build_dir)/my_proj.out]
|
||||
```
|
||||
|
||||
Then simply run `zbuild` and it will build (or rebuild, if out of date) the final binary.
|
||||
In particular the `examples/simple_c/zbuild.yaml` is a fully documented example that helps you understand how zbuild works.
|
||||
|
||||
# Installation
|
||||
|
||||
You may download the latest release from the [releases page](https://github.com/Zenithsiz/zbuild/releases).
|
||||
|
||||
You may also compile it yourself, with a nightly rust compiled (>= rustc 1.66.0-nightly (432abd86f 2022-09-20), may work with older) and install it by:
|
||||
You may also compile it yourself, with a nightly rust compiled (>= rustc 1.68.0-nightly (9c07efe84 2022-12-16), may work with older) and install it by:
|
||||
|
||||
1. Clone the repo
|
||||
|
||||
|
||||
1
examples/simple_c/.gitignore
vendored
Normal file
1
examples/simple_c/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
build/
|
||||
4
examples/simple_c/src/a.c
Normal file
4
examples/simple_c/src/a.c
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
extern void f();
|
||||
|
||||
int main() { f(); }
|
||||
3
examples/simple_c/src/b.c
Normal file
3
examples/simple_c/src/b.c
Normal file
@ -0,0 +1,3 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void f() { printf("Hello, world!"); }
|
||||
54
examples/simple_c/zbuild.yaml
Normal file
54
examples/simple_c/zbuild.yaml
Normal file
@ -0,0 +1,54 @@
|
||||
# Global aliases
|
||||
# These are aliases that may be used in the whole manifest.
|
||||
# You can reference them by using `$(<name>)` at any point.
|
||||
alias:
|
||||
build_dir: build
|
||||
src_dir: src
|
||||
|
||||
# Default targets
|
||||
# These are the targets (i.e. files / rules) that will be built
|
||||
# when no command line arguments are given.
|
||||
default:
|
||||
- $(build_dir)/my_proj.out
|
||||
|
||||
# Rules
|
||||
# zbuild will examine these to figure out how to build any target
|
||||
rules:
|
||||
# Each rule has a unique name, used only for it's identification
|
||||
compile_o:
|
||||
# Rule aliases
|
||||
# Rules may contain scoped aliases, specific to the rule.
|
||||
alias:
|
||||
my_alias: ...
|
||||
|
||||
# Output items
|
||||
#
|
||||
# `^(...)` can be used on the output items to create a "pattern".
|
||||
# When finding how to build a target, each rule's output will be tested against
|
||||
# the target. For example, if `build/a.o` is being checked, `^(name)` will become
|
||||
# `a`. This can then be used on the rest of the rule, such as the dependencies.
|
||||
out: [$(build_dir)/^(name).o]
|
||||
|
||||
# Dependencies
|
||||
# These are the items that your rule requires.
|
||||
# There are several types of dependencies, see the guide for more detail
|
||||
deps: [$(src_dir)/^(name).c]
|
||||
|
||||
# Execution
|
||||
#
|
||||
# Specifies an array of commands to execute to build this rule. Each command is an array of arguments. It will not be passed to a shell, but instead be executed as-is
|
||||
exec:
|
||||
- [mkdir, -p, $(build_dir)]
|
||||
- [gcc, $(src_dir)/^(name).c, -c, -o, $(build_dir)/^(name).o]
|
||||
|
||||
compile_out:
|
||||
out: [$(build_dir)/my_proj.out]
|
||||
deps: [$(build_dir)/a.o, $(build_dir)/b.o]
|
||||
|
||||
exec:
|
||||
- [gcc, $(build_dir)/a.o, $(build_dir)/b.o, -o, $(build_dir)/my_proj.out]
|
||||
|
||||
# Rules don't need outputs & dependencies, they can simply be executables
|
||||
clean:
|
||||
exec:
|
||||
- [rm, -rf, $(build_dir)]
|
||||
Loading…
x
Reference in New Issue
Block a user