Skip to content
Merged
38 changes: 25 additions & 13 deletions build-profiling-ffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,39 @@ ARG_FEATURES=""
run_tests=true

usage() {
echo "Usage: `basename "$0"` [-h] [-f FEATURES] [-T] dest-dir"
echo "Usage: `basename "$0"` [-h] [-f FEATURES] [-t TRIPLET] [-s] dest-dir"
echo
echo "Options:"
echo " -h This help text"
echo " -f FEATURES Enable specified features (comma separated if more than one)"
echo " -T Skip checks after building"
echo " -t TRIPLET Target triplet to build for, defaults to host triplet"
echo " -s Skip tests after building"
exit $1
}

while getopts f:hT flag
while getopts f:ht:s flag
do
case "${flag}" in
f)
ARG_FEATURES=${OPTARG}
shift
shift
# Split comma-separated values into array
IFS=',' read -ra FEATURE_ARRAY <<< "${OPTARG}"
ARG_FEATURES=("${FEATURE_ARRAY[@]}")
;;
h)
usage 0
;;
T)
t)
target=${OPTARG}
;;
s)
run_tests=false
shift
;;
esac
done

# Shift the processed options to get to the destination directory
shift $((OPTIND-1))

if test -z "${1:-}"; then
usage 1
fi
Expand All @@ -59,7 +65,9 @@ fi
mkdir -v -p "$destdir/include/datadog" "$destdir/lib/pkgconfig" "$destdir/cmake"

version=$(awk -F\" '$1 ~ /^version/ { print $2 }' < profiling-ffi/Cargo.toml)
target="$(rustc -vV | awk '/^host:/ { print $2 }')"
if [ -z ${target+x} ]; then
target="$(rustc -vV | awk '/^host:/ { print $2 }')"
fi
shared_library_suffix=".so"
static_library_suffix=".a"
library_prefix="lib"
Expand Down Expand Up @@ -149,8 +157,8 @@ if [[ "$symbolizer" -eq 1 ]]; then
FEATURES+=("symbolizer")
fi

if [[ ! -z ${ARG_FEATURES} ]]; then
FEATURES+=($ARG_FEATURES)
if [[ ! -z ${ARG_FEATURES:-} ]]; then
FEATURES+=("${ARG_FEATURES[@]}")
fi

FEATURES=$(IFS=, ; echo "${FEATURES[*]}")
Expand Down Expand Up @@ -246,7 +254,7 @@ if [[ "$symbolizer" -eq 1 ]]; then
# Copy the blazesym header separately because The blazesym header isn't auto-generated by cbindgen
# so we don't need to remove definitions that are already present in `common.h` using dedup_headers
cp "$CARGO_TARGET_DIR/include/datadog/blazesym.h" "$destdir/include/datadog/blazesym.h"
fi
fi


# Don't build the crashtracker on windows
Expand All @@ -260,7 +268,11 @@ if [[ "$target" != "x86_64-pc-windows-msvc" ]]; then
[ -d $CRASHTRACKER_BUILD_DIR ] && rm -r $CRASHTRACKER_BUILD_DIR
mkdir -p $CRASHTRACKER_BUILD_DIR
cd $CRASHTRACKER_BUILD_DIR
cmake -S $CRASHTRACKER_SRC_DIR -DDatadog_ROOT=$ABS_DESTDIR
if [[ "$target" == "x86_64-apple-darwin" ]]; then
cmake -S $CRASHTRACKER_SRC_DIR -DDatadog_ROOT=$ABS_DESTDIR -DCMAKE_OSX_ARCHITECTURES=x86_64
else
cmake -S $CRASHTRACKER_SRC_DIR -DDatadog_ROOT=$ABS_DESTDIR
fi
cmake --build .
mkdir -p $ABS_DESTDIR/bin
cp libdatadog-crashtracking-receiver $ABS_DESTDIR/bin
Expand Down
14 changes: 11 additions & 3 deletions builder/src/crashtracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ impl CrashTracker {

let mut crashtracker_dir = project_root();
crashtracker_dir.push("crashtracker");
let _dst = cmake::Config::new(crashtracker_dir.to_str().unwrap())
let mut config = cmake::Config::new(crashtracker_dir.to_str().unwrap());
let config = config
.define("Datadog_ROOT", datadog_root.to_str().unwrap())
.define("CMAKE_INSTALL_PREFIX", self.target_dir.to_string())
.build();
.define("CMAKE_INSTALL_PREFIX", self.target_dir.to_string());

let config = if self.arch.as_ref() == "x86_64-apple-darwin" {
config.define("CMAKE_OSX_ARCHITECTURES", "x86_64")
} else {
config
};

let _dst = config.build();
}

Ok(())
Expand Down
Loading