diff --git a/scripts/play.sh b/scripts/play.sh index 4b24c63..e055d95 100755 --- a/scripts/play.sh +++ b/scripts/play.sh @@ -2,7 +2,7 @@ set -e EXAMPLE="" -BUILD_ARGS="" +BUILD_ARGS="-F dylib" FILE="workspace/target/debug/app" ENV_VARS="" CMD_ARGS="" @@ -31,10 +31,29 @@ else TARGET_PATH="$FILE" fi +function patch_elf() { + local elfdata=$(readelf -d $TARGET_PATH) + local libstd=$(echo $elfdata | grep -Po "libstd-[\d\w]+.so") + local libbevy_dylib=$(echo $elfdata | grep -Po "libbevy_dylib-[\d\w]+\.so") + local deps_dir="./workspace/target/debug/deps" + + # rsync libstd and libbevy_dylib as assets to psync server + # this will change every time we rebuild + local dylib_path="./workspace/target/debug/libbevy_dylib.so" + # but this only changes when the toolchain changes + local stdlib_path="$(find "$(rustc --print sysroot)" -name "$libstd")" + rsync -avzr -e "/usr/bin/ssh -l psync -p 5022" -L --progress --mkpath $dylib_path $stdlib_path "$PSYNC_SERVER_IP:/home/psync/lib" + + # patch elf file + patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 "$TARGET_PATH" + patchelf --replace-needed "$libbevy_dylib" "libbevy_dylib.so" "$TARGET_PATH" + patchelf --set-rpath "/home/psync/lib" "$TARGET_PATH" +} + if [ -n "${SSH_CLIENT:-}" ]; then - patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 --remove-rpath "$TARGET_PATH" + patch_elf set -x - PSYNC_LOG=debug uvx --from cubething_psync psync \ + uvx --from cubething_psync psync \ "$TARGET_PATH" -e "${ENV_VARS}" -a "${CMD_ARGS}" -A "${ASSETS}" else set -x