forked from shadaj/tree-sitter-c2rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranspile.sh
37 lines (25 loc) · 1.08 KB
/
transpile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# build c2rust with:
# nix shell nixpkgs#llvm_15.dev nixpkgs#llvmPackages_15.libclang.lib nixpkgs#llvmPackages_15.libclang.dev nixpkgs#llvmPackages_15.clang
# export LIBCLANG_PATH=/nix/store/...-clang-...-lib/lib (from PATH)
# rustup run 1.80.1 cargo install c2rust --version 0.17.0 --locked --force
rm lib/src/*.rs
rm -rf lib/binding_rust/core_wrapper/core
c2rust transpile --emit-modules compile_commands.json
mv lib/src/lib.rs lib/src/api_raw.rs
sed -i "s/use ::libc;/use std::os;/g" lib/src/*.rs
sed -i "s/ as bool/ != 0/g" lib/src/*.rs
sed -i "s/type_0/type_/g" lib/src/*.rs
cargo run -p process_c2rust
mkdir lib/binding_rust/core_wrapper/core
mv lib/src/*.rs lib/binding_rust/core_wrapper/core/
output_path=lib/binding_rust/core_wrapper/core/defines.rs
header_path='lib/include/tree_sitter/api.h'
defines=(
TREE_SITTER_LANGUAGE_VERSION
TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
)
for define in ${defines[@]}; do
define_value=$(egrep "#define $define (.*)" $header_path | cut -d' ' -f3)
echo "pub const $define: u32 = $define_value;" >> $output_path
done
cargo +nightly fmt --all