Skip to content

Commit 805e379

Browse files
committed
root: add BUILD.md
1 parent da95945 commit 805e379

File tree

5 files changed

+127
-3
lines changed

5 files changed

+127
-3
lines changed

BUILD.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Build Instructions
2+
3+
Answering "how do I build Wuffs" depends on what exactly you mean by "Wuffs":
4+
5+
1. The Wuffs library (e.g. image decoders) in C/C++ form.
6+
2. Its example programs (e.g. jsonptr).
7+
3. The Wuffs toolchain (e.g. Wuffs-to-C compiler/proof-checker).
8+
4. The Wuffs library in Wuffs form (converting it to C/C++ code).
9+
5. Everything.
10+
11+
12+
## Quick Start
13+
14+
The rest of this document assumes that you've already checked out and moved
15+
into the Wuffs repository's directory, like this:
16+
17+
```
18+
git clone https://github.com/google/wuffs.git
19+
cd wuffs
20+
```
21+
22+
If you just want to kick the metaphorical tyres:
23+
24+
```
25+
./build-example.sh example/jsonptr
26+
gen/bin/example-jsonptr test/data/rfc-6901-json-pointer.json
27+
```
28+
29+
30+
## Building the Wuffs Library (in C/C++ Form)
31+
32+
There's no build step, in that there's no "configure and make" step needed
33+
before moving on to building the example programs.
34+
35+
To elaborate, transpiling (converting Wuffs-the-library from `*.wuffs` form
36+
into a single `*.c` file) isn't done by whoever *checks out* the Wuffs
37+
repository. It's done by whoever *checks in* code changes.
38+
39+
Wuffs-the-library is provided as [single file C
40+
library](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt). The
41+
example programs just `#include` that file directly.
42+
43+
For your own projects, just copy `release/c/wuffs-$VERSION.c` to your directory
44+
and add that file to your pre-existing build system, or compile an `*.o` object
45+
file directly like below. Remember to define the `WUFFS_IMPLEMENTATION` macro
46+
to compile all of the C code in that single file, not just the "header" part.
47+
48+
```
49+
# Most developers won't have to do this. It just demonstrates how to produce
50+
# wuffs-v0.3.o directly from a C/C++ compiler.
51+
gcc -c -DWUFFS_IMPLEMENTATION -O3 release/c/wuffs-v0.3.c
52+
```
53+
54+
55+
## Building the Example Programs
56+
57+
Just run your favorite C/C++ compiler (e.g. `gcc` or `g++`) on the
58+
`example/foo/*.{c,cc}` file. Pass `-O3` or equivalent for an optimized build:
59+
60+
```
61+
gcc -O3 example/bzcat/bzcat.c -o my-bzcat
62+
./my-bzcat < test/data/romeo.txt.bz2
63+
```
64+
65+
Some example programs require additional libraries:
66+
67+
```
68+
g++ example/imageviewer/imageviewer.cc -lxcb -lxcb-image -lxcb-render -lxcb-render-util
69+
70+
g++ example/sdl-imageviewer/sdl-imageviewer.cc -lSDL2 -lSDL2_image
71+
```
72+
73+
The `build-example.sh` script (an alternative to running your favorite C/C++
74+
compiler directly) takes care of having to remember those additional libraries.
75+
76+
```
77+
./build-example.sh example/sdl-imageviewer
78+
gen/bin/example-sdl-imageviewer test/data/hat.jpeg
79+
```
80+
81+
Building the fuzzers are similar, using `build-fuzz.sh` instead of
82+
`build-example.sh`.
83+
84+
85+
## Building the Wuffs Toolchain
86+
87+
Most developers won't have to do this. See the sections above instead.
88+
89+
But after editing `lang/check/*.go` files, do this:
90+
91+
```
92+
go install ./cmd/wuffs*
93+
```
94+
95+
96+
## Building the Wuffs library (from its Wuffs Form)
97+
98+
Most developers won't have to do this. See the sections above instead.
99+
100+
But after editing `std/jpeg/*.wuffs` files, do this:
101+
102+
```
103+
wuffs gen std/...
104+
```
105+
106+
107+
## Building Everything (All of the Above, Plus Tests, Benchmarks, Etc)
108+
109+
Most developers won't have to do this. See the sections above instead.
110+
111+
But before sending a Pull Request, do this:
112+
113+
```
114+
./build-all.sh
115+
```

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,15 @@ wuffs test: some tests failed
181181
- `hello-wuffs-c` holds an example program for Wuffs the Language.
182182

183183

184+
# Building
185+
186+
See the [BUILD](/BUILD.md) instructions.
187+
188+
184189
# Documentation
185190

186191
- [Getting Started](/doc/getting-started.md). **Start here** if you want to
187-
play but aren't sure how.
192+
play but aren't sure how (and [BUILD](/BUILD.md) doesn't help).
188193
- [Background](/doc/background.md).
189194
- [Benchmarks](/doc/benchmarks.md).
190195
- [Binary Size](/doc/binary-size.md).
@@ -241,4 +246,4 @@ owned by Google.
241246

242247
---
243248

244-
Updated on January 2023.
249+
Updated on June 2023.

build-all.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
# cd wuffs
3737
# gcc ./example/zcat/zcat.c
3838
# ./a.out < ./test/data/romeo.txt.gz
39+
#
40+
# See BUILD.md for more discussion.
3941

4042
if [ ! -e wuffs-root-directory.txt ]; then
4143
echo "$0 should be run from the Wuffs root directory."

build-example.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# ----------------
1717

18-
# See build-all.sh for commentary.
18+
# See BUILD.md and build-all.sh for more discussion.
1919

2020
if [ ! -e wuffs-root-directory.txt ]; then
2121
echo "$0 should be run from the Wuffs root directory."

example/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ examples. To check out and build just one, such as `jsonptr`:
2424
When re-building, you only need the last of those three lines. To run it:
2525

2626
gen/bin/example-jsonptr test/data/json-things.unformatted.json
27+
28+
See also the top-level [BUILD](/BUILD.md) instructions.

0 commit comments

Comments
 (0)