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
8 changes: 5 additions & 3 deletions crates/init/ls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
#![doc = r##"<!-- Absolutely cursed hacks:
SOURCE="$0" NAME=$(basename "$0" .rs) DIR=$(realpath $(dirname "$0"))
exec "$(dirname "$0")/../ulib/compile.sh" "$0" <<END_MANIFEST
NAME="$(basename "$0" .rs)"
DIR=$(cd "$(dirname "$0")" && pwd -P)
ULIB_DIR="$(git rev-parse --show-toplevel)/crates/ulib"
exec "$ULIB_DIR/compile.sh" "$0" <<END_MANIFEST
[package]
name = "$NAME"
version = "0.1.0"
Expand All @@ -12,7 +14,7 @@ name = "$NAME"
path = "$DIR/$NAME.rs"

[dependencies]
ulib = { path = "$DIR/../ulib" }
ulib = { path = "$ULIB_DIR" }

[profile.standalone]
inherits = "release"
Expand Down
8 changes: 5 additions & 3 deletions crates/init/sharedMemTest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
#![doc = r##"<!-- Absolutely cursed hacks:
SOURCE="$0" NAME=$(basename "$0" .rs) DIR=$(realpath $(dirname "$0"))
exec "$(dirname "$0")/../ulib/compile.sh" "$0" <<END_MANIFEST
NAME="$(basename "$0" .rs)"
DIR=$(cd "$(dirname "$0")" && pwd -P)
ULIB_DIR="$(git rev-parse --show-toplevel)/crates/ulib"
exec "$ULIB_DIR/compile.sh" "$0" <<END_MANIFEST
[package]
name = "$NAME"
version = "0.1.0"
Expand All @@ -12,7 +14,7 @@ name = "$NAME"
path = "$DIR/$NAME.rs"

[dependencies]
ulib = { path = "$DIR/../ulib" }
ulib = { path = "$ULIB_DIR" }

[profile.standalone]
inherits = "release"
Expand Down
8 changes: 5 additions & 3 deletions crates/init/shell.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
#![doc = r##"<!-- Absolutely cursed hacks:
SOURCE="$0" NAME=$(basename "$0" .rs) DIR=$(realpath $(dirname "$0"))
exec "$(dirname "$0")/../ulib/compile.sh" "$0" <<END_MANIFEST
NAME="$(basename "$0" .rs)"
DIR=$(cd "$(dirname "$0")" && pwd -P)
ULIB_DIR="$(git rev-parse --show-toplevel)/crates/ulib"
exec "$ULIB_DIR/compile.sh" "$0" <<END_MANIFEST
[package]
name = "$NAME"
version = "0.1.0"
Expand All @@ -12,7 +14,7 @@ name = "$NAME"
path = "$DIR/$NAME.rs"

[dependencies]
ulib = { path = "$DIR/../ulib" }
ulib = { path = "$ULIB_DIR" }

[profile.standalone]
inherits = "release"
Expand Down
36 changes: 22 additions & 14 deletions crates/ulib/compile.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env bash

set -e
SOURCE=$(realpath "$1")
NAME=$(basename "$SOURCE" .rs)
RELATIVE=$(realpath --relative-to=. "$SOURCE" || echo "$SOURCE")
ULIB_DIR=$(cd "$(dirname -- "$0")" && pwd -P)
SOURCE_DIR=$(cd "$(dirname -- "$1")" && pwd -P)
SOURCE="$SOURCE_DIR/$(basename -- "$1")"
NAME=$(basename -- "$SOURCE" .rs)

MANIFEST="$(cat)"

LINKER_SCRIPT="$(dirname "$0")/script.ld"
LINKER_SCRIPT="$ULIB_DIR/script.ld"

TEMP_DIR="$(mktemp -d)"
trap 'rm -rf -- "$TEMP_DIR"' EXIT
Expand All @@ -26,13 +27,20 @@ CARGO_TARGET_DIR="$TARGET_DIR" RUSTC_BOOTSTRAP=1 cargo rustc \
-C link-arg=-T"${LINKER_SCRIPT}" -C link-args='-zmax-page-size=0x1000' \

BIN_PATH="${TARGET_DIR}/aarch64-unknown-none-softfloat/standalone/${NAME}"
cp "${BIN_PATH}" "${SOURCE%.rs}.elf"

# TODO: macos doesn't support realpath --relative-to, stat -c
SIZE=$(test -f "${SOURCE%.rs}.elf" && find "${SOURCE%.rs}.elf" -printf "%s")
SIZE=$(echo "${SIZE}" | python3 -c \
"(lambda f:f(f,float(input()),0))\
(lambda f,i,j:print('%.4g'%i,'BKMGTPE'[j]+'iB' if j else 'bytes')\
if i<1024 else f(f,i/1024,j+1))"
)
echo "Built ${RELATIVE%.rs}.elf, file size ${SIZE}"
ELF_FILE="${SOURCE%.rs}.elf"
cp "${BIN_PATH}" "$ELF_FILE"

if test -f "$ELF_FILE" ; then
# MacOS compat -- try everything, hope at least one works
SIZE=$(stat -c%s -- "$ELF_FILE" 2>/dev/null || stat -f%z -- "$ELF_FILE" 2>/dev/null || find "$ELF_FILE" -printf "%s")
SIZE=$(echo "${SIZE}" | python3 -c \
"(lambda f:f(f,float(input()),0))\
(lambda f,i,j:print('%.4g'%i,'BKMGTPE'[j]+'iB' if j else 'bytes')\
if i<1024 else f(f,i/1024,j+1))"
)
RELATIVE=$(realpath --relative-to=. -- "$SOURCE" || echo "$SOURCE")
echo "Built ${RELATIVE%.rs}.elf, file size ${SIZE}"
else
echo "Failed to build $ELF_FILE?"
exit 1
fi
Loading