Skip to content

Commit

Permalink
Use the ijar ZIP implementation in Blaze instead of libarchive
Browse files Browse the repository at this point in the history
This ZIP implementation is lightweight and rely on zlib for
compression. libarchive was a bit tricky to set-up so it's
better to use that one.

--
Change-Id: I607b492998572e834e095a4606eeb77c0b574542
Reviewed-on: https://bazel-review.googlesource.com/#/c/1410/
MOS_MIGRATED_REVID=94910072
  • Loading branch information
damienmg authored and philwo committed Jun 1, 2015
1 parent 14b437b commit eb6e903
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 182 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/.classpath
/.factorypath
/.idea/
/fromhost/
/base_workspace/bazel-bin
/base_workspace/bazel-genfiles
/base_workspace/bazel-out
Expand Down
2 changes: 1 addition & 1 deletion .travis/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if [[ $TRAVIS_OS_NAME = 'osx' ]]; then
brew install protobuf libarchive
else
sudo apt-get update -qq
sudo apt-get install -y protobuf-compiler libarchive-dev netcat-traditional
sudo apt-get install -y protobuf-compiler netcat-traditional
sudo update-alternatives --set nc /bin/nc.traditional
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export JAVA_OPTS="-Xmx3000m"
Expand Down
84 changes: 4 additions & 80 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,58 +71,6 @@ function log() {
fi
}

function write_fromhost_build() {
case "${PLATFORM}" in
linux)
cat << EOF > fromhost/BUILD
package(default_visibility = ["//visibility:public"])
cc_library(
name = "libarchive",
srcs = [],
hdrs = [],
)
EOF

;;
darwin)
if [[ -e $homebrew_header ]]; then
rm -f fromhost/*.[ah]
touch fromhost/empty.c
# For use with Homebrew.
archive_dir=$(dirname $(dirname $homebrew_header))
cp ${archive_dir}/lib/*.a ${archive_dir}/include/*.h fromhost/
cat << EOF > fromhost/BUILD
package(default_visibility = ["//visibility:public"])
cc_library(
name = "libarchive",
srcs = glob(["*.a"]) + ["empty.c"],
hdrs = glob(["*.h"]),
includes = ["."],
linkopts = ["-lxml2", "-liconv", "-lbz2", "-lz", ],
)
EOF

elif [[ -e $macports_header ]]; then
# For use with Macports.
archive_dir=$(dirname $(dirname $macports_header))
rm -f fromhost/*.[ah]
touch fromhost/empty.c
cp "${archive_dir}"/include/{archive.h,archive_entry.h} fromhost/
cp "${archive_dir}"/lib/{libarchive,liblzo2,liblzma,libcharset,libbz2,libxml2,libz,libiconv}.a \
fromhost/
cat << EOF > fromhost/BUILD
package(default_visibility = ["//visibility:public"])
cc_library(
name = "libarchive",
srcs = glob(["*.a"]) + ["empty.c"],
hdrs = glob(["*.h"]),
includes = ["."],
)
EOF
fi
esac
}

# Create symlinks so we can use tools and examples from the base_workspace.
base_workspace=$(pwd)/base_workspace
mkdir -p "$base_workspace"
Expand All @@ -133,7 +81,7 @@ rm -f "${base_workspace}/examples" && ln -s "$(pwd)/examples" "${base_workspace}
case "${PLATFORM}" in
linux)
# Sorry, no static linking on linux for now.
LDFLAGS="$(pkg-config libarchive --libs) -lrt $LDFLAGS"
LDFLAGS="-lz -lrt $LDFLAGS"
JNILIB="libunix.so"
MD5SUM="md5sum"
# JAVA_HOME must point to a Java 8 installation.
Expand All @@ -144,41 +92,21 @@ linux)
darwin)
JNILIB="libunix.dylib"
MD5SUM="md5"
LDFLAGS="-lz $LDFLAGS"
if [[ -z "$JAVA_HOME" ]]; then
JAVA_HOME="$(/usr/libexec/java_home -v 1.8+ 2> /dev/null)" \
|| fail "Could not find JAVA_HOME, please ensure a JDK (version 1.8+) is installed."
fi
PROTOC=${PROTOC:-third_party/protobuf/protoc.darwin}

homebrew_header=$(ls -1 $(brew --prefix libarchive 2>/dev/null)/include/archive.h 2>/dev/null | head -n1)
macports_header=$(port contents libarchive 2>/dev/null | grep /archive.h$ | xargs)
if [[ -e $homebrew_header ]]; then
# For use with Homebrew.
archive_dir=$(dirname $(dirname $homebrew_header))
ARCHIVE_CFLAGS="-I${archive_dir}/include"
LDFLAGS="-L${archive_dir}/lib -larchive $LDFLAGS"

elif [[ -e $macports_header ]]; then
# For use with Macports.
ARCHIVE_CFLAGS="-Ifromhost"
# Link libarchive statically
LDFLAGS="fromhost/libarchive.a fromhost/liblzo2.a \
fromhost/liblzma.a fromhost/libcharset.a \
fromhost/libbz2.a fromhost/libxml2.a \
fromhost/libz.a fromhost/libiconv.a \
$LDFLAGS"
else
log "WARNING: Could not find libarchive installation, proceeding bravely."
fi

;;

msys*|mingw*)
# Use a simplified platform string.
PLATFORM="mingw"
# Workaround for msys issue which causes omission of std::to_string.
CXXFLAGS="$CXXFLAGS -D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_DYNAMIC"
LDFLAGS="-larchive ${LDFLAGS}"
LDFLAGS="-lz $LDFLAGS"
MD5SUM="md5sum"
EXE_EXT=".exe"
PATHSEP=";"
Expand Down Expand Up @@ -207,11 +135,6 @@ esac
[[ -x "${PROTOC-}" ]] \
|| fail "Protobuf compiler not found in ${PROTOC-}"

mkdir -p fromhost
if [ ! -f fromhost/BUILD ]; then
write_fromhost_build
fi

test -z "$JAVA_HOME" && fail "JDK not found, please set \$JAVA_HOME."
rm -f tools/jdk/jdk && ln -s "${JAVA_HOME}" tools/jdk/jdk

Expand Down Expand Up @@ -239,6 +162,7 @@ src/main/cpp/util/md5.cc
src/main/cpp/util/numbers.cc
src/main/cpp/util/port.cc
src/main/cpp/util/strings.cc
third_party/ijar/zip.cc
)

NATIVE_CC_FILES=(
Expand Down
6 changes: 3 additions & 3 deletions site/docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ You can also add this line to your `~/.bashrc` file.
#### 3. Install required packages:

```
$ sudo apt-get install libarchive-dev pkg-config zip g++ zlib1g-dev
$ sudo apt-get install pkg-config zip g++ zlib1g-dev
```

#### 4. Build Bazel:
Expand Down Expand Up @@ -101,13 +101,13 @@ To build Bazel on Mac OS X:
#### 1. Install the required packages:

```
$ port install protobuf-cpp libarchive
$ port install protobuf-cpp
```

or

```
$ brew install protobuf libarchive
$ brew install protobuf
```

#### 2. Build Bazel:
Expand Down
2 changes: 1 addition & 1 deletion site/docs/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Next, open an MSYS2 shell (not the mingw32 or the mingw64 shell) either through
a shortcut or by running the `msys2_shell.bat`. Install the dependencies:

```bash
pacman -S libarchive-devel gcc mingw-w64-x86_64-gcc zip unzip git
pacman -S gcc mingw-w64-x86_64-gcc zip unzip git
```

The msys2 gcc will be used for building Bazel itself, the mingw-w64 gcc will
Expand Down
17 changes: 5 additions & 12 deletions src/main/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,13 @@ cc_binary(
"//src:darwin": [
],
"//conditions:default": [
"-larchive",
"-lrt",
],
}),
visibility = ["//src:__pkg__"],
deps = select({
"//src:darwin": [
":md5",
":util",
"//fromhost:libarchive",
],
"//conditions:default": [
":md5",
":util",
],
}),
deps = [
":md5",
":util",
"//third_party/ijar:zip",
],
)
Loading

0 comments on commit eb6e903

Please sign in to comment.