1# flex and bison binaries
2
3This folder contains the flex and bison binaries. We use these binaries to
4generate the ANGLE translator's lexer and parser.
5
6Use the script [`update_flex_bison_binaries.py`](update_flex_bison_binaries.py)
7to update the versions of these binaries in cloud storage. It must be run on
8Linux or Windows. It will update the SHAs for your platform. After running the
9script run `git commit` and then `git cl upload` to code review using the normal
10review process. You will also want to run
11[`scripts/run_code_generation.py`](../../scripts/run_code_generation.py) to
12update the generated files.
13
14Please update both Windows and Linux binaries at the same time. Use two CLs. One
15for each platform. Note that we don't currently support Mac for generating the
16lexer and parser files. If we do we should add a flex/bison download for Mac as
17well.
18
19Contact jmadill or syoussefi for any help with updating the binaries.
20
21## Updating flex and bison binaries
22
23This is expected to be a rare operation, and is currently done based on the
24following instructions.  Note: get the binaries first on windows, as only a
25single option is available, then build the binaries for the same version on
26Linux.
27
28### On Windows
29
30Install MSys2 (x86_64) from http://www.msys2.org/ on Windows.  `flex` should
31already be installed.  Install bison:
32
33```
34$ pacman -S bison
35```
36
37Note the versions of flex and bison so the same versions can be build on Linux.
38For example:
39
40```
41$ flex --version
42flex 2.6.4
43
44$ bison --version
45bison (GNU Bison) 3.3.2
46```
47
48The only dependencies from MSys2 should be the following:
49
50```
51msys-intl-8.dll
52msys-iconv-2.dll
53msys-2.0.dll
54```
55
56This can be verified with:
57
58```
59$ ldd /usr/bin/flex
60$ ldd /usr/bin/bison
61```
62
63Additionally, we need the binary for m4 at `/usr/bin/m4`.
64
65Copy all these 5 files to this directory:
66
67```
68$ cd angle/
69$ cp /usr/bin/flex.exe \
70     /usr/bin/bison.exe \
71     /usr/bin/m4.exe \
72     /usr/bin/msys-intl-8.dll \
73     /usr/bin/msys-iconv-2.dll \
74     /usr/bin/msys-2.0.dll \
75     tools/flex-bison/windows/
76```
77
78Upload the binaries:
79
80```
81$ cd angle/
82$ python tools/flex-bison/update_flex_bison_binaries.py
83```
84
85### On Linux
86
87```
88# Get the source of flex
89$ git clone https://github.com/westes/flex.git
90$ cd flex/
91# Checkout the same version as msys2 on windows
92$ git checkout v2.6.4
93# Build
94$ autoreconf -i
95$ mkdir build && cd build
96$ ../configure CFLAGS="-O2 -D_GNU_SOURCE"
97$ make -j
98```
99
100```
101# Get the source of bison
102$ curl http://ftp.gnu.org/gnu/bison/bison-3.3.2.tar.xz | tar -xJ
103$ cd bison-3.3.2
104# Build
105$ mkdir build && cd build
106$ ../configure CFLAGS="-O2"
107$ make -j
108```
109
110Note: Bison's [home page][Bison] lists ftp server and other mirrors.  If the
111above link is broken, replace with a mirror.
112
113Copy the 2 executables to this directory:
114
115```
116$ cd angle/
117$ cp /path/to/flex/build/src/flex \
118     /path/to/bison/build/src/bison \
119     tools/flex-bison/linux/
120```
121
122Upload the binaries:
123
124```
125$ cd angle/
126$ python tools/flex-bison/update_flex_bison_binaries.py
127```
128
129[Bison]: https://www.gnu.org/software/bison/
130