Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions bazel/EXTERNAL_DEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@ Dependencies between external libraries can use the standard Bazel dependency
resolution logic, using the `$(location)` shell extension to resolve paths
to binaries, libraries, headers, etc.

# Adding external dependencies to Envoy (build recipe)

This is the older style of adding dependencies. It uses shell scripts to build and install
dependencies into a shared directory prefix. This should no longer be used unless there are
extenuating circumstances.

1. Add a build recipe X in [`ci/build_container/build_recipes`](../ci/build_container/build_recipes)
for developer-local and CI external dependency build flows.
2. Add a build target Y in [`ci/prebuilt/BUILD`](../ci/prebuilt/BUILD) to consume the headers and
libraries produced by the build recipe X.
3. Add a map from target Y to build recipe X in [`target_recipes.bzl`](target_recipes.bzl).
4. Reference your new external dependency in some `envoy_cc_library` via Y in the `external_deps`
attribute.
5. `bazel test //test/...`

# Updating an external dependency version

1. If the dependency is a build recipe, update the build recipe in
Expand Down
10 changes: 10 additions & 0 deletions bazel/foreign_cc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ cc_library(
],
)

configure_make(
name = "luajit",
configure_command = "build.py",
lib_source = "@com_github_luajit_luajit//:all",
make_commands = [],
static_libraries = [
"libluajit-5.1.a",
],
)

envoy_cmake_external(
name = "ares",
cache_entries = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
#!/bin/bash

set -e

if [[ "${OS}" == "Windows_NT" ]]; then
exit 0
fi

SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"

$($SCRIPT_DIR/versions.py luajit)

FILE_NAME=$(basename "$FILE_URL")

curl "$FILE_URL" -sLo "$FILE_NAME" \
&& echo "$FILE_SHA256" "$FILE_NAME" | sha256sum --check
tar xf "$FILE_NAME"

cd "$FILE_PREFIX"

# Fixup Makefile with things that cannot be set via env var.
cat > luajit_make.diff << 'EOF'
diff --git a/src/Makefile b/src/Makefile
index f56465d..3f4f2fa 100644
--- a/src/Makefile
Expand Down Expand Up @@ -65,11 +43,34 @@ index f56465d..3f4f2fa 100644

##############################################################################
EOF

patch -p1 < luajit_make.diff

# Default MACOSX_DEPLOYMENT_TARGET is 10.4, which will fail the build at link time on macOS 10.14:
# ld: library not found for -lgcc_s.10.4
# This doesn't affect other platforms
MACOSX_DEPLOYMENT_TARGET=10.6 DEFAULT_CC=${CC} TARGET_CFLAGS=${CFLAGS} TARGET_LDFLAGS=${CFLAGS} \
CFLAGS="" make V=1 PREFIX="$THIRDPARTY_BUILD" install
diff --git a/build.py b/build.py
new file mode 100755
index 0000000..9c71271
--- /dev/null
+++ b/build.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+import argparse
+import os
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--prefix")
+ args = parser.parse_args()
+ os.chdir(os.path.dirname(os.path.realpath(__file__)))
+
+ os.environ["MACOSX_DEPLOYMENT_TARGET"] = "10.6"
+ os.environ["DEFAULT_CC"] = os.environ.get("CC", "")
+ os.environ["TARGET_CFLAGS"] = os.environ.get("CFLAGS", "")
+ os.environ["TARGET_LDFLAGS"] = os.environ.get("CFLAGS", "")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lizan Is this intentional or just a bug carried over?
Isn't TARGET_LDFLAGS supposed to be overridden by os.environ.get("LDFLAGS")

was TARGET_LDFLAGS=${CFLAGS} just to address that MacOSX bug mentioned in old code comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure, this is just to replicate what we had in luajit.sh.

What is the macOS bug, the MACOSX_DEPLOYMENT_TARGET one is not relevant to this environment variable.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The

-   MACOSX_DEPLOYMENT_TARGET=10.6 DEFAULT_CC=${CC} TARGET_CFLAGS=${CFLAGS} TARGET_LDFLAGS=${CFLAGS} 

Was the first place where TARGET_LDFLAGS was overridden with CFLAGS, and I think this small mistake was carried over in

+    os.environ["TARGET_LDFLAGS"] = os.environ.get("CFLAGS", "")

+ os.environ["CFLAGS"] = ""
+ # LuaJIT compile process build a tool `buildvm` and use it, building `buildvm` with ASAN
+ # will cause LSAN detect its leak and fail the build, set exitcode to 0 to make LSAN doesn't
+ # fail on it.
+ os.environ["LSAN_OPTIONS"] = "exitcode=0"
+
+ os.system('make V=1 PREFIX="{}" install'.format(args.prefix))
+
+main()
+
105 changes: 18 additions & 87 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,6 @@ def _repository_impl(name, **kwargs):
**kwargs
)

def _build_recipe_repository_impl(ctxt):
# on Windows, all deps use rules_foreign_cc
if ctxt.os.name.upper().startswith("WINDOWS"):
return

# modify the recipes list based on the build context
recipes = _apply_dep_blacklist(ctxt, ctxt.attr.recipes)

# Setup the build directory with links to the relevant files.
ctxt.symlink(Label("//bazel:repositories.sh"), "repositories.sh")
ctxt.symlink(
Label("//ci/build_container:build_and_install_deps.sh"),
"build_and_install_deps.sh",
)
ctxt.symlink(Label("//ci/build_container:recipe_wrapper.sh"), "recipe_wrapper.sh")
ctxt.symlink(Label("//ci/build_container:Makefile"), "Makefile")
for r in recipes:
ctxt.symlink(
Label("//ci/build_container/build_recipes:" + r + ".sh"),
"build_recipes/" + r + ".sh",
)
ctxt.symlink(Label("//ci/prebuilt:BUILD"), "BUILD")

# Run the build script.
print("Fetching external dependencies...")
result = ctxt.execute(
["./repositories.sh"] + recipes,
quiet = False,
)
print(result.stdout)
print(result.stderr)
print("External dep build exited with return code: %d" % result.return_code)
if result.return_code != 0:
print("\033[31;1m\033[48;5;226m External dependency build failed, check above log " +
"for errors and ensure all prerequisites at " +
"https://github.com/envoyproxy/envoy/blob/master/bazel/README.md#quick-start-bazel-build-for-developers are met.")

# This error message doesn't appear to the user :( https://github.com/bazelbuild/bazel/issues/3683
fail("External dep build failed")

def _default_envoy_build_config_impl(ctx):
ctx.file("WORKSPACE", "")
ctx.file("BUILD.bazel", "")
Expand Down Expand Up @@ -191,43 +151,7 @@ def _envoy_api_deps():
actual = "@six_archive//:six",
)

def envoy_dependencies(path = "@envoy_deps//", skip_targets = []):
envoy_repository = repository_rule(
implementation = _build_recipe_repository_impl,
environ = [
"CC",
"CXX",
"CFLAGS",
"CXXFLAGS",
"LD_LIBRARY_PATH",
],
# Don't pretend we're in the sandbox, we do some evil stuff with envoy_dep_cache.
local = True,
attrs = {
"recipes": attr.string_list(),
},
)

# Ideally, we wouldn't have a single repository target for all dependencies, but instead one per
# dependency, as suggested in #747. However, it's much faster to build all deps under a single
# recursive make job and single make jobserver.
recipes = depset()
for t in TARGET_RECIPES:
if t not in skip_targets:
recipes += depset([TARGET_RECIPES[t]])

envoy_repository(
name = "envoy_deps",
recipes = recipes.to_list(),
)

for t in TARGET_RECIPES:
if t not in skip_targets:
native.bind(
name = t,
actual = path + ":" + t,
)

def envoy_dependencies(skip_targets = []):
# Treat Envoy's overall build config as an external repo, so projects that
# build Envoy as a subcomponent can easily override the config.
if "envoy_build_config" not in native.existing_rules().keys():
Expand Down Expand Up @@ -267,6 +191,7 @@ def envoy_dependencies(path = "@envoy_deps//", skip_targets = []):
_com_github_gperftools_gperftools()
_com_github_jbeder_yaml_cpp()
_com_github_libevent_libevent()
_com_github_luajit_luajit()
_com_github_madler_zlib()
_com_github_nanopb_nanopb()
_com_github_nghttp2_nghttp2()
Expand Down Expand Up @@ -697,6 +622,22 @@ def _com_github_google_jwt_verify():
actual = "@com_github_google_jwt_verify//:jwt_verify_lib",
)

def _com_github_luajit_luajit():
location = REPOSITORY_LOCATIONS["com_github_luajit_luajit"]
http_archive(
name = "com_github_luajit_luajit",
build_file_content = BUILD_ALL_CONTENT,
patches = ["@envoy//bazel/foreign_cc:luajit.patch"],
patch_args = ["-p1"],
patch_cmds = ["chmod u+x build.py"],
**location
)

native.bind(
name = "luajit",
actual = "@envoy//bazel/foreign_cc:luajit",
)

def _com_github_gperftools_gperftools():
location = REPOSITORY_LOCATIONS["com_github_gperftools_gperftools"]
http_archive(
Expand All @@ -714,16 +655,6 @@ def _com_github_gperftools_gperftools():
def _foreign_cc_dependencies():
_repository_impl("rules_foreign_cc")

def _apply_dep_blacklist(ctxt, recipes):
newlist = []
skip_list = []
if _is_linux_ppc(ctxt):
skip_list += PPC_SKIP_TARGETS.keys()
for t in recipes:
if t not in skip_list:
newlist.append(t)
return newlist

def _is_linux(ctxt):
return ctxt.os.name == "linux"

Expand Down
42 changes: 0 additions & 42 deletions bazel/repositories.sh

This file was deleted.

5 changes: 5 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ REPOSITORY_LOCATIONS = dict(
strip_prefix = "grpc-1.16.1",
urls = ["https://github.com/grpc/grpc/archive/v1.16.1.tar.gz"],
),
com_github_luajit_luajit = dict(
sha256 = "409f7fe570d3c16558e594421c47bdd130238323c9d6fd6c83dedd2aaeb082a8",
strip_prefix = "LuaJIT-2.1.0-beta3",
urls = ["https://github.com/LuaJIT/LuaJIT/archive/v2.1.0-beta3.tar.gz"],
),
com_github_nanopb_nanopb = dict(
sha256 = "b8dd5cb0d184d424ddfea13ddee3f7b0920354334cbb44df434d55e5f0086b12",
strip_prefix = "nanopb-0.3.9.2",
Expand Down
1 change: 0 additions & 1 deletion bazel/target_recipes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
# target in //ci/prebuilt/BUILD to the underlying build recipe in
# ci/build_container/build_recipes.
TARGET_RECIPES = {
"luajit": "luajit",
}
4 changes: 1 addition & 3 deletions ci/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ local_repository(
path = "/source",
)

envoy_dependencies(
path = "@envoy//ci/prebuilt",
)
envoy_dependencies()

# TODO(htuch): Roll this into envoy_dependencies()
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
Expand Down
5 changes: 2 additions & 3 deletions ci/WORKSPACE.filter.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ local_repository(
load("@envoy//bazel:repositories.bzl", "envoy_dependencies", "GO_VERSION")
load("@envoy//bazel:cc_configure.bzl", "cc_configure")

envoy_dependencies(
path = "@envoy//ci/prebuilt",
)
envoy_dependencies()

# TODO(htuch): Roll this into envoy_dependencies()
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()
Expand Down
13 changes: 0 additions & 13 deletions ci/build_container/BUILD

This file was deleted.

3 changes: 1 addition & 2 deletions ci/build_container/Dockerfile-centos
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM centos:7

COPY ./build_and_install_deps.sh ./recipe_wrapper.sh ./Makefile ./build_container_common.sh /
COPY ./build_container_common.sh /
COPY WORKSPACE /bazel-prebuilt/
COPY ./api /bazel-prebuilt/api
COPY ./bazel /bazel-prebuilt/bazel
COPY ./build_recipes /build_recipes

COPY ./build_container_centos.sh /

Expand Down
3 changes: 1 addition & 2 deletions ci/build_container/Dockerfile-ubuntu
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM ubuntu:xenial

COPY ./build_and_install_deps.sh ./recipe_wrapper.sh ./Makefile ./build_container_common.sh /
COPY ./build_container_common.sh /
COPY WORKSPACE /bazel-prebuilt/
COPY ./api /bazel-prebuilt/api
COPY ./bazel /bazel-prebuilt/bazel
COPY ./build_recipes /build_recipes

COPY ./build_container_ubuntu.sh /

Expand Down
Loading