Use third-party instead of installing deps
[hiphop-php.git] / hphp / hack / src / cbindgen.sh
blob45af8d4a103ab768b640756d24b9c74b8509a334
1 #!/usr/bin/env bash
3 set -euo pipefail
5 top="$(pwd)"
6 if [ "$(echo "$top" | grep -c "fbcode\$")" -ne 1 ]
7 then
8 echo "This script should be run from fbsource/fbcode."
9 exit 1
12 DIR=hphp/hack/.cargo_vendor
13 if [ ! -d "$DIR" ];
14 then
15 echo "Need to generate .cargo_vendor"
16 echo " Try 'hphp/hack/scripts/facebook/cargo_fetch.sh'"
17 read -r -p " Perform these steps? [y/n] " input
18 case $input in
19 [yY][eE][sS]|[yY])
20 echo " Perfoming steps"
21 hphp/hack/scripts/facebook/cargo_fetch.sh
24 echo " No steps performed. Exiting."
25 exit 2
27 esac
30 set -x
32 cargo="buck run fbsource//third-party/rust:cargo-cargo --"
33 cbindgen="buck run fbsource//third-party/rust:cbindgen-cbindgen --"
35 # 'cargo update' ensures the existing Cargo.lock files contain the latest versions
37 # ffi.h
38 (cd hphp/hack/src/utils/ffi && \
39 $cargo update && \
40 $cbindgen --config ./cbindgen_ffi.toml \
41 --crate ffi \
42 --output "$top/hphp/hack/src/utils/ffi/ffi.h")
44 # hhbc_id.h
45 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_hhbc_id && \
46 $cargo update && \
47 $cbindgen --config ../../cbindgen_hhbc_id.toml \
48 --crate hhbc_by_ref_hhbc_id \
49 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_id.h")
51 # hhbc_label.h
52 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_label && \
53 $cargo update && \
54 $cbindgen --config ../../cbindgen_hhbc_label.toml \
55 --crate hhbc_by_ref_label \
56 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_label.h")
58 # hhbc_local.h
59 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_local && \
60 $cargo update && \
61 $cbindgen --config ../../cbindgen_hhbc_local.toml \
62 --crate hhbc_by_ref_local \
63 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_local.h")
65 # hhbc_runtime.h
66 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_runtime && \
67 $cargo update && \
68 $cbindgen --config ../../cbindgen_hhbc_runtime.toml \
69 --crate hhbc_by_ref_runtime \
70 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_runtime.h")
72 # hhbc_ast.h
73 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_hhbc_ast && \
74 $cargo update && \
75 $cbindgen --config ../../cbindgen_hhbc_ast.toml \
76 --crate hhbc_by_ref_hhbc_ast \
77 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_ast.h")
79 # hhbc_instruction_sequence.h
80 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_instruction_sequence && \
81 $cargo update && \
82 $cbindgen --config ../../cbindgen_hhbc_instruction_sequence.toml \
83 --crate hhbc_by_ref_instruction_sequence \
84 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_instruction_sequence.h")
86 # hhbc_symbol_refs_state.h
87 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_symbol_refs_state && \
88 $cargo update && \
89 $cbindgen --config ../../cbindgen_hhbc_symbol_refs_state.toml \
90 --crate hhbc_by_ref_symbol_refs_state \
91 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_symbol_refs_state.h")
93 # hhbc_hhas_symbol_refs.h
94 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_hhas_symbol_refs && \
95 $cargo update && \
96 $cbindgen --config ../../cbindgen_hhbc_hhas_symbol_refs.toml \
97 --crate hhbc_by_ref_hhas_symbol_refs \
98 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_symbol_refs.h")
100 # hhbc_hhas_constant.h
101 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_hhas_constant && \
102 $cargo update && \
103 $cbindgen --config ../../cbindgen_hhbc_hhas_constant.toml \
104 --crate hhbc_by_ref_hhas_constant \
105 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_constant.h")
107 # hhbc_hhas_type.h
108 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_hhas_type && \
109 $cargo update && \
110 $cbindgen --config ../../cbindgen_hhbc_hhas_type.toml \
111 --crate hhbc_by_ref_hhas_type \
112 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_type.h")
113 # hhbc_hhas_attribute.h
114 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_hhas_attribute && \
115 $cargo update && \
116 $cbindgen --config ../../cbindgen_hhbc_hhas_attribute.toml \
117 --crate hhbc_by_ref_hhas_attribute \
118 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_attribute.h")
120 # hhbc_hhas_adata.h
121 (cd hphp/hack/src/hhbc/hhbc_by_ref/cargo/hhbc_by_ref_hhas_adata && \
122 $cargo update && \
123 $cbindgen --config ../../cbindgen_hhbc_hhas_adata.toml \
124 --crate hhbc_by_ref_hhas_adata \
125 --output "$top/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_adata.h")
127 signscript="$top/../xplat/python/signedsource_lib/signedsource.py"
128 eval "${signscript}" sign "${top}"/hphp/hack/src/utils/ffi/ffi.h
129 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_id.h
130 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_label.h
131 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_local.h
132 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_runtime.h
133 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_ast.h
134 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_instruction_sequence.h
135 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_symbol_refs_state.h
136 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_symbol_refs.h
137 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_constant.h
138 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_type.h
139 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_attribute.h
140 eval "${signscript}" sign "${top}"/hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_adata.h
142 # Quick sanity check: Does a program that includes these headers compile?
143 cat > main.cpp <<EOF
144 #include "hphp/hack/src/hhbc/hhbc_by_ref/hhbc_instruction_sequence.h"
145 #include "hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_symbol_refs.h"
146 #include "hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_constant.h"
147 #include "hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_type.h"
148 #include "hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_attribute.h"
149 #include "hphp/hack/src/hhbc/hhbc_by_ref/hhbc_hhas_adata.h"
151 #include <iostream>
153 int main() {
154 using namespace HPHP::hackc::hhbc::ast;
156 InstrSeq _b6;
157 HhasSymbolRefs _b7;
158 HhasConstant _b8;
159 HhasAttribute _b9;
160 Info _c1;
161 HhasAdata _b10;
163 std::cout << "Ok!" << std::endl;
164 return 0;
167 g++ -std=c++14 main.cpp -I . -o run && ./run
168 rm -f ./main.cpp ./run