diff --git a/ports/geckolib/tools/.gitignore b/ports/geckolib/tools/.gitignore new file mode 100644 index 00000000000..ba50cb6cd5d --- /dev/null +++ b/ports/geckolib/tools/.gitignore @@ -0,0 +1,2 @@ +llvm/ +rust-bindgen/ diff --git a/ports/geckolib/tools/README.md b/ports/geckolib/tools/README.md new file mode 100644 index 00000000000..f920c75c85b --- /dev/null +++ b/ports/geckolib/tools/README.md @@ -0,0 +1,30 @@ +# GeckoLib tools + +This directory contains mostly simple tools for working with +[stylo](https://public.etherpad-mozilla.org/p/stylo). + +Some scripts require [multirust](https://github.com/brson/multirust) in order to +work. + +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` + +This uses downloads a custom version of bindgen, up to date to generate the +bindings, and uses the custom `clang` to build it. + +It will also rebuild it if it's already downloaded. + +## `regen_bindings.sh` + +This will regenerate the bindings for the `ServoBindings.h` file in your gecko +build (which are in `ports/geckolib/bindings.rs`). + +## `regen_style_structs.sh` + +This will generate the bindings for Gecko's style structs. These bindings are a +work in progress, and are not in master yet. diff --git a/ports/geckolib/tools/build_custom_clang.sh b/ports/geckolib/tools/build_custom_clang.sh index 40b3c86f5aa..7bf98741060 100755 --- a/ports/geckolib/tools/build_custom_clang.sh +++ b/ports/geckolib/tools/build_custom_clang.sh @@ -1,7 +1,7 @@ #!/bin/bash # Run in the tools directory. -cd `dirname $0` +cd "$(dirname $0)" # Don't run twice. if [ -d llvm ]; then diff --git a/ports/geckolib/tools/regen_bindings.sh b/ports/geckolib/tools/regen_bindings.sh index 32b36b3b59d..ed99d5904a3 100755 --- a/ports/geckolib/tools/regen_bindings.sh +++ b/ports/geckolib/tools/regen_bindings.sh @@ -1,10 +1,10 @@ #!/bin/bash # Run in the tools directory. -cd `dirname $0` +cd "$(dirname $0)" if [ $# -ne 1 ]; then - echo "Usage: $0 /path/to/objdir/" + echo "Usage: $0 /path/to/gecko/objdir" exit 1 fi @@ -15,13 +15,13 @@ if [ ! -d rust-bindgen ]; then fi export RUST_BACKTRACE=1 -export LIBCLANG_PATH=`pwd`/llvm/build/Release+Asserts/lib -export DYLD_LIBRARY_PATH=`pwd`/llvm/build/Release+Asserts/lib -export LD_LIBRARY_PATH=`pwd`/llvm/build/Release+Asserts/lib -export DIST_INCLUDE=$1/dist/include +export LIBCLANG_PATH="$(pwd)/llvm/build/Release+Asserts/lib" +export DYLD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib" +export LD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib" +export DIST_INCLUDE="$1/dist/include" # Check for the include directory. -if [ ! -d $DIST_INCLUDE ]; then +if [ ! -d "$DIST_INCLUDE" ]; then echo "$DIST_INCLUDE: directory not found" exit 1 fi @@ -31,4 +31,8 @@ fi # library in DYLD_LIBRARY_PATH. # # /Applications/Xcode.app/Contents/Developer/usr/bin/lldb -- -./rust-bindgen/target/debug/bindgen -x c++ -std=gnu++0x -I$DIST_INCLUDE -o ../bindings.rs $DIST_INCLUDE/mozilla/ServoBindings.h +./rust-bindgen/target/debug/bindgen \ + -x c++ -std=gnu++0x \ + "-I$DIST_INCLUDE" \ + -o ../bindings.rs \ + "$DIST_INCLUDE/mozilla/ServoBindings.h" diff --git a/ports/geckolib/tools/regen_style_structs.sh b/ports/geckolib/tools/regen_style_structs.sh index 73dbe75b987..5e0bdd45afa 100755 --- a/ports/geckolib/tools/regen_style_structs.sh +++ b/ports/geckolib/tools/regen_style_structs.sh @@ -4,7 +4,7 @@ cd `dirname $0` if [ $# -ne 1 ]; then - echo "Usage: $0 /path/to/objdir/" + echo "Usage: $0 /path/to/gecko/objdir" exit 1 fi @@ -16,11 +16,10 @@ fi # Need to find a way to avoid hardcoding these export RUST_BACKTRACE=1 -export LIBCLANG_PATH=`pwd`/llvm/build/Release+Asserts/lib -export DYLD_LIBRARY_PATH=`pwd`/llvm/build/Release+Asserts/lib -export LD_LIBRARY_PATH=`pwd`/llvm/build/Release+Asserts/lib -export DIST_INCLUDE=$1/dist/include -CLANG_SEARCH_DIRS=$(clang++ -print-search-dirs | grep 'libraries: ' | cut -d = -f 2) +export LIBCLANG_PATH="$(pwd)/llvm/build/Release+Asserts/lib" +export DYLD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib" +export LD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib" +export DIST_INCLUDE="$1/dist/include" CLANG_SEARCH_DIRS=$(clang++ -E -x c++ - -v < /dev/null 2>&1 | awk '{ \ if ($0 == "#include <...> search starts here:") \ in_headers = 1; \ @@ -33,17 +32,31 @@ CLANG_SEARCH_DIRS=$(clang++ -E -x c++ - -v < /dev/null 2>&1 | awk '{ \ }' | sed -e s/:$//g) # Check for the include directory. -if [ ! -d $DIST_INCLUDE ]; then +if [ ! -d "$DIST_INCLUDE" ]; then echo "$DIST_INCLUDE: directory not found" exit 1 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. +PLATFORM_DEPENDENT_DEFINES=""; +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 -- -./rust-bindgen/target/debug/bindgen -x c++ -std=gnu++0x -ignore-functions -allow-unknown-types \ - $CLANG_SEARCH_DIRS \ - -I$DIST_INCLUDE -I$DIST_INCLUDE/nspr -DDEBUG=1 -DTRACING=1 -DOS_POSIX=1 -DOS_MACOSX=1 -DMOZILLA_INTERNAL_API -DIMPL_LIBXUL \ - -include $1/mozilla-config.h -o ../gecko_style_structs.rs $DIST_INCLUDE/nsStyleStruct.h +./rust-bindgen/target/debug/bindgen \ + -x c++ -std=gnu++0x \ + -ignore-functions -allow-unknown-types \ + $CLANG_SEARCH_DIRS \ + "-I$DIST_INCLUDE" "-I$DIST_INCLUDE/nspr" \ + $PLATFORM_DEPENDENT_DEFINES \ + -DDEBUG=1 -DTRACING=1 -DOS_POSIX=1 \ + -DMOZILLA_INTERNAL_API -DIMPL_LIBXUL \ + -include "$1/mozilla-config.h" \ + -o ../gecko_style_structs.rs \ + "$DIST_INCLUDE/nsStyleStruct.h" diff --git a/ports/geckolib/tools/setup_bindgen.sh b/ports/geckolib/tools/setup_bindgen.sh index d33c4d5ab88..ce3851daa1b 100755 --- a/ports/geckolib/tools/setup_bindgen.sh +++ b/ports/geckolib/tools/setup_bindgen.sh @@ -1,23 +1,25 @@ #!/bin/bash # Run in the tools directory. -cd `dirname $0` +cd "$(dirname $0)" + +# Setup and build bindgen. +export LIBCLANG_PATH="$(pwd)/llvm/build/Release+Asserts/lib" + # Make sure we have a custom clang set up. -if [ ! -d llvm ]; then +if [ ! -d "$LIBCLANG_PATH" ]; then echo "Custom LLVM/Clang not found. Run build_custom_clang.sh first." exit 1 fi # Check for multirust if [ ! -x "$(command -v multirust)" ]; then - echo 'multirust must be installed.' + echo "multirust must be installed." exit 1 fi -# Setup and build bindgen. -export LIBCLANG_PATH=`pwd`/llvm/build/Release+Asserts/lib -# Don't run twice. +# Don't try to clone twice. if [ ! -d rust-bindgen ]; then git clone https://github.com/bholley/rust-bindgen.git cd rust-bindgen