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
20 changes: 10 additions & 10 deletions docker/build/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,16 @@ function parse_arguments() {
}

function print_usage() {
echo "Usage:"
echo "${TAB}$0 -f <Dockerfile> [options]"
echo "Options:"
echo "${TAB}-c,--clean Disable Docker cache (--no-cache)"
echo "${TAB}-m,--mode Apollo install mode (build | download). Default: ${INSTALL_MODE}"
echo "${TAB}-g,--geo Geographical location (cn | us) for software sources. Default: ${TARGET_GEOLOC}"
echo "${TAB}-t,--timestamp Specify a fixed timestamp for image tags (YYYYMMDD_HHMM). Default: current time"
echo "${TAB}-s,--no-squash Do not squash Docker layers. Default: Squash layers"
echo "${TAB}--dry Dry run only (print build commands without executing)"
echo "${TAB}-h,--help Show this help message"
echo "Usage: $0 -f <Dockerfile> [options]"
echo "Options:"
echo "${TAB}-c,--clean Disable Docker cache"
echo "${TAB}-m,--mode Install mode (build|download), default: ${INSTALL_MODE}"
echo "${TAB}-g,--geo Geo location (cn|us), default: ${TARGET_GEOLOC}"
echo "${TAB}-t,--timestamp Image tag timestamp (YYYYMMDD_HHMM), default: now"
echo "${TAB}--dry Dry run (show build commands only)"
echo "${TAB}-h,--help Show this help"
echo
echo "Tip: To pre-download packages, use a local HTTP server (python3 -m http.server 8388)."
}

function main() {
Expand Down
3 changes: 3 additions & 0 deletions docker/build/installers/install_libtorch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ function install_libtorch_cpp() {
# Use mv instead of cp -r for better efficiency
mv libtorch/* "${INSTALL_DIR}/"

# Add runtime library path
ensure_ld_path "${INSTALL_DIR}/lib"

# Clean up downloaded files
popd > /dev/null
rm -rf "${DOWNLOAD_DIR}"
Expand Down
28 changes: 25 additions & 3 deletions docker/build/installers/installer_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ function source_date_epoch_setup() {
|| date -u "$DATE_FMT")
}

function ensure_ld_path() {
local lib_path="$1"
local target_file="${APOLLO_LD_FILE}"

if [ -z "$lib_path" ]; then
echo "Error: empty lib_path parameter"
return 1
fi

if [ ! -f "$target_file" ]; then
echo "$lib_path" >> "$target_file"
return 0
fi

if ! grep -Fxq "$lib_path" "$target_file"; then
echo "$lib_path" >> "$target_file"
else
echo "Path '$lib_path' is already present in $target_file"
fi
}

function apollo_environ_setup() {
: "${SOURCE_DATE_EPOCH:=$(source_date_epoch_setup)}"

Expand All @@ -79,9 +100,10 @@ function apollo_environ_setup() {
if [ ! -d "${SYSROOT_DIR}" ]; then
mkdir -p ${SYSROOT_DIR}/{bin,include,lib,share}
fi
if [ ! -f "${APOLLO_LD_FILE}" ]; then
echo "${SYSROOT_DIR}/lib" | tee -a "${APOLLO_LD_FILE}"
fi

# Add runtime library path
ensure_ld_path "${SYSROOT_DIR}/lib"
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

The return value of ensure_ld_path is not checked; if updating the ld file fails, the script will continue silently. Consider adding || exit 1 or handling errors to avoid silent misconfigurations.

Suggested change
ensure_ld_path "${SYSROOT_DIR}/lib"
if ! ensure_ld_path "${SYSROOT_DIR}/lib"; then
error "Failed to update runtime library path with ensure_ld_path."
exit 1
fi

Copilot uses AI. Check for mistakes.

if [ ! -f "${APOLLO_PROFILE}" ] && [ -f "/opt/apollo/rcfiles/apollo.sh.sample" ]; then
cp -f /opt/apollo/rcfiles/apollo.sh.sample "${APOLLO_PROFILE}"
echo "add_to_path ${SYSROOT_DIR}/bin" >> "${APOLLO_PROFILE}"
Expand Down
90 changes: 58 additions & 32 deletions third_party/opencv/opencv.BUILD
Original file line number Diff line number Diff line change
@@ -1,56 +1,82 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library")

licenses(["notice"])

package(default_visibility = ["//visibility:public"])
# ---------- shared helper: headers ----------
cc_library(
name = "opencv_headers",
hdrs = glob(["include/opencv4/opencv2/**/*.h"]),
includes = ["include/opencv4"],
visibility = ["//visibility:public"],
)

#TODO(storypku): split opencv into seperate components to speed up build
# e.g., opencv_imgproc/opencv_highgui/...
# ---------- core ----------
cc_import(
name = "core_so",
shared_library = "lib/libopencv_core.so.4.4",
visibility = ["//visibility:public"],
)

cc_library(
name = "core",
includes = ["."],
linkopts = [
"-L/opt/apollo/sysroot/lib",
"-lopencv_core",
deps = [
":opencv_headers",
":core_so"
],
linkstatic = False,
visibility = ["//visibility:public"],
)

cc_library(
name = "highgui",
includes = ["."],
linkopts = [
"-L/opt/apollo/sysroot/lib",
"-lopencv_highgui",
],
# Note(storypku): dependency relation derived from ldd
deps = [
":core",
":imgproc",
],
# ---------- imgproc ----------
cc_import(
name = "imgproc_so",
shared_library = "lib/libopencv_imgproc.so.4.4",
visibility = ["//visibility:public"],
)

cc_library(
name = "imgproc",
includes = ["."],
linkopts = [
"-L/opt/apollo/sysroot/lib",
"-lopencv_imgproc",
],
deps = [
":core",
":opencv_headers",
":core",
":imgproc_so"
],
linkstatic = False,
visibility = ["//visibility:public"],
)

# ---------- imgcodecs ----------
cc_import(
name = "imgcodecs_so",
shared_library = "lib/libopencv_imgcodecs.so.4.4",
visibility = ["//visibility:public"],
)

cc_library(
name = "imgcodecs",
includes = ["."],
linkopts = [
"-L/opt/apollo/sysroot/lib",
"-lopencv_imgcodecs",
deps = [
":opencv_headers",
":core",
":imgproc",
":imgcodecs_so"
],
linkstatic = False,
visibility = ["//visibility:public"],
)

# ---------- highgui ----------
cc_import(
name = "highgui_so",
shared_library = "lib/libopencv_highgui.so.4.4",
visibility = ["//visibility:public"],
)

cc_library(
name = "highgui",
deps = [
":opencv_headers",
":core",
":imgproc",
":highgui_so",
],
linkstatic = False,
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion third_party/opencv/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def repo():
native.new_local_repository(
name = "opencv",
build_file = clean_dep("//third_party/opencv:opencv.BUILD"),
path = "/opt/apollo/sysroot/include/opencv4",
path = "/opt/apollo/sysroot",
)
42 changes: 30 additions & 12 deletions third_party/osqp/osqp.BUILD
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_import")

package(default_visibility = ["//visibility:public"])
# TODO: Starting with Bazel 8.3, cc_import supports strip_include_prefix.
# At that point we can collapse the current two-stage setup (headers cc_library + cc_import .so)
# into one cc_import rule using:
# strip_include_prefix = "include"
# or
# includes = ["include"]
# to expose headers properly and simplify maintenance.

licenses(["notice"])

# 1. Header files
cc_library(
name = "osqp",
include_prefix = "osqp",
includes = [
".",
],
linkopts = [
"-L/opt/apollo/sysroot/lib",
"-losqp",
],
name = "osqp_headers",
hdrs = glob(["include/osqp/**/*.h"]),
includes = ["include"],
visibility = ["//visibility:public"],
)

# 2. Shared library
cc_import(
name = "osqp_so",
shared_library = "lib/libosqp.so", # Relative to new_local_repository.path
visibility = ["//visibility:public"],
)

# 3. Aggregate target
cc_library(
name = "osqp",
deps = [
":osqp_headers",
":osqp_so"
],
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion third_party/osqp/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def repo():
native.new_local_repository(
name = "osqp",
build_file = clean_dep("//third_party/osqp:osqp.BUILD"),
path = "/opt/apollo/sysroot/include",
path = "/opt/apollo/sysroot",
)
Loading