mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Simplify binding generation and remove the need for a custom clang.
This commit is contained in:
parent
402f79559b
commit
fb0237d85c
5 changed files with 47 additions and 80 deletions
|
@ -8,10 +8,6 @@ work.
|
||||||
|
|
||||||
You can see a description of them below.
|
You can see a description of them below.
|
||||||
|
|
||||||
## `build_custom_clang.sh`
|
|
||||||
|
|
||||||
Download a patched LLVM which is needed to use bindgen properly with C++.
|
|
||||||
|
|
||||||
## `setup_bindgen.sh`
|
## `setup_bindgen.sh`
|
||||||
|
|
||||||
This uses downloads a custom version of bindgen, up to date to generate the
|
This uses downloads a custom version of bindgen, up to date to generate the
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Run in the tools directory.
|
|
||||||
cd "$(dirname $0)"
|
|
||||||
|
|
||||||
# Don't run twice.
|
|
||||||
if [ -d llvm ]; then
|
|
||||||
echo "llvm directory already exists."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Download and build a custom llvm
|
|
||||||
git clone https://github.com/llvm-mirror/llvm
|
|
||||||
cd llvm
|
|
||||||
git checkout release_38
|
|
||||||
cd tools
|
|
||||||
git clone https://github.com/llvm-mirror/clang
|
|
||||||
cd clang
|
|
||||||
git checkout release_38
|
|
||||||
cd ../.. # llvm root dir
|
|
||||||
mkdir build
|
|
||||||
cd build
|
|
||||||
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
|
|
||||||
make -j8
|
|
|
@ -14,11 +14,19 @@ if [ ! -d rust-bindgen ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export RUST_BACKTRACE=1
|
# Check for /usr/include
|
||||||
export LIBCLANG_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
|
if [ ! -d /usr/include ]; then
|
||||||
export DYLD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
|
echo "/usr/include doesn't exist. Mac users may need to run xcode-select --install."
|
||||||
export LD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
|
exit 1
|
||||||
export DIST_INCLUDE="$1/dist/include"
|
fi
|
||||||
|
|
||||||
|
if [ "$(uname)" == "Linux" ]; then
|
||||||
|
PLATFORM_DEPENDENT_DEFINES+="-DOS_LINUX";
|
||||||
|
LIBCLANG_PATH=/usr/lib/llvm-3.8/lib;
|
||||||
|
else
|
||||||
|
PLATFORM_DEPENDENT_DEFINES+="-DOS_MACOSX";
|
||||||
|
LIBCLANG_PATH=`brew --prefix llvm38`/lib/llvm-3.8/lib;
|
||||||
|
fi
|
||||||
|
|
||||||
# Prevent bindgen from generating opaque types for the gecko style structs.
|
# Prevent bindgen from generating opaque types for the gecko style structs.
|
||||||
export MAP_GECKO_STRUCTS=""
|
export MAP_GECKO_STRUCTS=""
|
||||||
|
@ -30,26 +38,24 @@ for STRUCT in nsStyleFont nsStyleColor nsStyleList nsStyleText \
|
||||||
nsStyleOutline nsStyleXUL nsStyleSVGReset nsStyleColumn nsStyleEffects
|
nsStyleOutline nsStyleXUL nsStyleSVGReset nsStyleColumn nsStyleEffects
|
||||||
do
|
do
|
||||||
MAP_GECKO_STRUCTS=$MAP_GECKO_STRUCTS"-blacklist-type $STRUCT "
|
MAP_GECKO_STRUCTS=$MAP_GECKO_STRUCTS"-blacklist-type $STRUCT "
|
||||||
MAP_GECKO_STRUCTS=$MAP_GECKO_STRUCTS"-raw-line 'use gecko_style_structs::$STRUCT;'$'\n' "
|
MAP_GECKO_STRUCTS=$MAP_GECKO_STRUCTS"-raw-line 'use gecko_style_structs::$STRUCT;' "
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check for the include directory.
|
# Check for the include directory.
|
||||||
|
export DIST_INCLUDE="$1/dist/include"
|
||||||
if [ ! -d "$DIST_INCLUDE" ]; then
|
if [ ! -d "$DIST_INCLUDE" ]; then
|
||||||
echo "$DIST_INCLUDE: directory not found"
|
echo "$DIST_INCLUDE: directory not found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export RUST_BACKTRACE=1
|
||||||
|
|
||||||
# We need to use 'eval' here to make MAP_GECKO_STRUCTS evaluate properly as
|
# We need to use 'eval' here to make MAP_GECKO_STRUCTS evaluate properly as
|
||||||
# multiple arguments.
|
# multiple arguments.
|
||||||
#
|
|
||||||
# Uncomment the following line to run rust-bindgen in a debugger on mac.
|
|
||||||
# The absolute path is required to allow launching lldb with an untrusted
|
|
||||||
# library in DYLD_LIBRARY_PATH.
|
|
||||||
#
|
|
||||||
# /Applications/Xcode.app/Contents/Developer/usr/bin/lldb --
|
|
||||||
eval ./rust-bindgen/target/debug/bindgen \
|
eval ./rust-bindgen/target/debug/bindgen \
|
||||||
-x c++ -std=gnu++0x \
|
-x c++ -std=gnu++0x \
|
||||||
"-I$DIST_INCLUDE" \
|
"-I$DIST_INCLUDE" \
|
||||||
|
$PLATFORM_DEPENDENT_DEFINES \
|
||||||
-o ../bindings.rs \
|
-o ../bindings.rs \
|
||||||
-no-type-renaming \
|
-no-type-renaming \
|
||||||
"$DIST_INCLUDE/mozilla/ServoBindings.h" \
|
"$DIST_INCLUDE/mozilla/ServoBindings.h" \
|
||||||
|
|
|
@ -14,49 +14,34 @@ if [ ! -d rust-bindgen ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Need to find a way to avoid hardcoding these
|
# Check for /usr/include
|
||||||
export RUST_BACKTRACE=1
|
if [ ! -d /usr/include ]; then
|
||||||
export LIBCLANG_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
|
echo "/usr/include doesn't exist. Mac users may need to run xcode-select --install."
|
||||||
export DYLD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
|
exit 1
|
||||||
export LD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
|
fi
|
||||||
export DIST_INCLUDE="$1/dist/include"
|
|
||||||
CLANG_SEARCH_DIRS=$(clang++ -E -x c++ - -v < /dev/null 2>&1 | awk '{ \
|
if [ "$(uname)" == "Linux" ]; then
|
||||||
if ($0 == "#include <...> search starts here:") \
|
PLATFORM_DEPENDENT_DEFINES+="-DOS_LINUX";
|
||||||
in_headers = 1; \
|
LIBCLANG_PATH=/usr/lib/llvm-3.8/lib;
|
||||||
else if ($0 == "End of search list.") \
|
else
|
||||||
in_headers = 0; \
|
PLATFORM_DEPENDENT_DEFINES+="-DOS_MACOSX";
|
||||||
else if (in_headers == 1) { \
|
LIBCLANG_PATH=`brew --prefix llvm38`/lib/llvm-3.8/lib;
|
||||||
gsub(/^[ \t]+/, "", $0); \
|
fi
|
||||||
gsub(/[ \t].+$/, "", $0); \
|
|
||||||
printf " -isystem %s", $0; \
|
|
||||||
}
|
|
||||||
}' | sed -e s/:$//g)
|
|
||||||
|
|
||||||
# Check for the include directory.
|
# Check for the include directory.
|
||||||
|
export DIST_INCLUDE="$1/dist/include"
|
||||||
if [ ! -d "$DIST_INCLUDE" ]; then
|
if [ ! -d "$DIST_INCLUDE" ]; then
|
||||||
echo "$DIST_INCLUDE: directory not found"
|
echo "$DIST_INCLUDE: directory not found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PLATFORM_DEPENDENT_DEFINES="";
|
export RUST_BACKTRACE=1
|
||||||
if [ "$(uname)" == "Linux" ]; then
|
|
||||||
PLATFORM_DEPENDENT_DEFINES+="-DOS_LINUX";
|
|
||||||
else
|
|
||||||
PLATFORM_DEPENDENT_DEFINES+="-DOS_MACOSX";
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Uncomment the following line to run rust-bindgen in a debugger on mac. The
|
|
||||||
# absolute path is required to allow launching lldb with an untrusted library
|
|
||||||
# in DYLD_LIBRARY_PATH.
|
|
||||||
#
|
|
||||||
# /Applications/Xcode.app/Contents/Developer/usr/bin/lldb --
|
|
||||||
# gdb -ex "break rust_panic" -ex run --args \
|
|
||||||
# -enable-cxx-namespaces \
|
|
||||||
./rust-bindgen/target/debug/bindgen \
|
./rust-bindgen/target/debug/bindgen \
|
||||||
-o ../gecko_style_structs.rs \
|
-o ../gecko_style_structs.rs \
|
||||||
-x c++ -std=gnu++0x \
|
-x c++ -std=gnu++0x \
|
||||||
-allow-unknown-types \
|
-allow-unknown-types \
|
||||||
$CLANG_SEARCH_DIRS \
|
|
||||||
"-I$DIST_INCLUDE" "-I$DIST_INCLUDE/nspr" \
|
"-I$DIST_INCLUDE" "-I$DIST_INCLUDE/nspr" \
|
||||||
"-I$1/../nsprpub/pr/include" \
|
"-I$1/../nsprpub/pr/include" \
|
||||||
$PLATFORM_DEPENDENT_DEFINES \
|
$PLATFORM_DEPENDENT_DEFINES \
|
||||||
|
|
|
@ -4,17 +4,21 @@
|
||||||
cd "$(dirname $0)"
|
cd "$(dirname $0)"
|
||||||
|
|
||||||
# Setup and build bindgen.
|
# Setup and build bindgen.
|
||||||
export LIBCLANG_PATH="$(pwd)/llvm/build/lib"
|
if [ "$(uname)" == "Linux" ]; then
|
||||||
export LD_LIBRARY_PATH="$(pwd)/llvm/build/lib"
|
LIBCLANG_PATH=/usr/lib/llvm-3.8/lib;
|
||||||
export DYLD_LIBRARY_PATH="$(pwd)/llvm/build/lib"
|
else
|
||||||
|
LIBCLANG_PATH=`brew --prefix llvm38`/lib/llvm-3.8/lib;
|
||||||
|
|
||||||
# Make sure we have a custom clang set up.
|
|
||||||
if [ ! -d "$LIBCLANG_PATH" ]; then
|
|
||||||
echo "Custom LLVM/Clang not found. Run build_custom_clang.sh first."
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Make sure we have llvm38.
|
||||||
|
if [ ! -x "$(command -v clang++-3.8)" ]; then
|
||||||
|
echo "llmv38 must be installed. Mac users should |brew install llvm38|, Linux varies by distro."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
export LD_LIBRARY_PATH=$LIBCLANG_PATH
|
||||||
|
export DYLD_LIBRARY_PATH=$LIBCLANG_PATH
|
||||||
|
|
||||||
# Check for multirust
|
# Check for multirust
|
||||||
if [ ! -x "$(command -v multirust)" ]; then
|
if [ ! -x "$(command -v multirust)" ]; then
|
||||||
echo "multirust must be installed."
|
echo "multirust must be installed."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue