Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

profiling: update ffi build script to cross compile 32 bit on 64 bit linux #866

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
28 changes: 21 additions & 7 deletions build-profiling-ffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ 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] [-T] dest-dir"
echo
echo "Options:"
echo " -h This help text"
echo " -f FEATURES Enable specified features (comma separated if more than one)"
echo " -t TRIPLET Target triplet to build for, defaults to host triplet"
echo " -T Skip checks after building"
exit $1
}

while getopts f:hT flag
while getopts f:ht:T flag
do
case "${flag}" in
f)
Comment on lines -31 to 35
Copy link
Member

Choose a reason for hiding this comment

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

Two notes here:

  • I think we're misusing the shift -- it actually breaks if we try to pass more than one setting now; e.g. -f foo -t triplet or -T -t triplet. My bash-foo isn't great but this suggests how we may fix it. I think it has "worked" until now since nobody tried to use -f with -T, but it seems reasonable to want to combine -f and -t for instance?

  • As a script UX thing, consider using something other than -t for the triplet, to avoid the collision with the test. Maybe -a (arch?) or -c (cpu) or something like that? Alternatively, rename the -T to something else, I think that works too :)

Expand All @@ -39,6 +40,11 @@ do
h)
usage 0
;;
t)
target=${OPTARG}
shift
shift
;;
T)
run_tests=false
shift
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 All @@ -77,7 +85,7 @@ symbolizer=0
# provided. At least on Alpine, libgcc_s may not even exist in the users'
# images, so -static-libgcc is recommended there.
case "$target" in
"x86_64-alpine-linux-musl"|"aarch64-alpine-linux-musl")
"x86_64-alpine-linux-musl"|"aarch64-alpine-linux-musl"|"i686-alpine-linux-musl")
expected_native_static_libs=" -lssp_nonshared -lgcc_s -lc"
native_static_libs=" -lssp_nonshared -lc"
# on alpine musl, Rust adds some weird runpath to cdylibs
Expand All @@ -94,7 +102,7 @@ case "$target" in
fix_macos_rpath=1
;;

"x86_64-unknown-linux-gnu"|"aarch64-unknown-linux-gnu")
"x86_64-unknown-linux-gnu"|"aarch64-unknown-linux-gnu"|"i686-unknown-linux-gnu")
expected_native_static_libs=" -ldl -lrt -lpthread -lgcc_s -lc -lm -lrt -lpthread -lutil -ldl -lutil"
native_static_libs=" -ldl -lrt -lpthread -lc -lm -lrt -lpthread -lutil -ldl -lutil"
symbolizer=1
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,13 @@ 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" =~ ^i686 ]]; then
CFLAGS=-m32 CXXFLAGS=-m32 cmake -S $CRASHTRACKER_SRC_DIR -DDatadog_ROOT=$ABS_DESTDIR
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
6 changes: 5 additions & 1 deletion ddcommon/src/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ fn now() -> u64 {
tv_nsec: 0,
};
unsafe { libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut ts) };
(ts.tv_sec * TIME_PER_SECOND + ts.tv_nsec) as u64
#[cfg(target_pointer_width = "64")]
let result = (ts.tv_sec * TIME_PER_SECOND + ts.tv_nsec) as u64;
#[cfg(target_pointer_width = "32")]
let result = (ts.tv_sec as i64 * TIME_PER_SECOND + ts.tv_nsec as i64) as u64;
result
};
now
}
Expand Down
Loading