Skip to content

Commit

Permalink
[all] make location-independent binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Dec 11, 2022
1 parent aad1556 commit 6a799e0
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 37 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,22 @@ each compiler, with standard "release mode" flags (see each language's

```
$ ./utils/bench.py
rs / release: Emulated 13230 frames in 10.00s (1323fps)
rs / lto : Emulated 13018 frames in 10.00s (1302fps)
cpp / release: Emulated 12752 frames in 10.00s (1275fps)
nim / speed : Emulated 8163 frames in 10.00s (816fps)
nim / release: Emulated 8160 frames in 10.00s (815fps)
zig / release: Emulated 7472 frames in 10.00s (747fps)
nim / release: Emulated 6228 frames in 10.00s (622fps)
go / release: Emulated 4948 frames in 10.00s (495fps)
pxd / release: Emulated 3778 frames in 10.00s (378fps)
py / mypyc : Emulated 833 frames in 10.01s (83fps)
php / opcache: Emulated 600 frames in 10.00s (60fps)
php / release: Emulated 251 frames in 10.01s (25fps)
py / release: Emulated 95 frames in 10.04s (9fps)
zig / safe : Emulated 38 frames in 10.16s (4fps)
rs / lto : Emulated 15763 frames in 10.00s (1576fps)
rs / release: Emulated 13183 frames in 10.00s (1318fps)
cpp / release: Emulated 12966 frames in 10.00s (1297fps)
zig / release: Emulated 8792 frames in 10.00s (879fps)
nim / speed : Emulated 8127 frames in 10.00s (812fps)
nim / release: Emulated 6161 frames in 10.00s (616fps)
cpp / debug : Emulated 5693 frames in 10.00s (569fps)
go / release: Emulated 5040 frames in 10.00s (504fps)
pxd / release: Emulated 3792 frames in 10.00s (379fps)
nim / debug : Emulated 1968 frames in 10.00s (196fps)
rs / debug : Emulated 1676 frames in 10.00s (168fps)
py / mypyc : Emulated 887 frames in 10.01s (89fps)
php / opcache: Emulated 613 frames in 10.01s (61fps)
php / release: Emulated 255 frames in 10.01s (25fps)
py / release: Emulated 101 frames in 10.06s (10fps)
zig / safe : Emulated 40 frames in 10.00s (4fps)
```

Also if you spot some bit of code that is weirdly slow and making your favourite
Expand Down
2 changes: 1 addition & 1 deletion cpp/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

cd $(dirname $0)
BUILDDIR=build/$(uname)-$(uname -m)
BUILDDIR=build/release/$(uname)-$(uname -m)
cmake -DCMAKE_BUILD_TYPE=Release -B $BUILDDIR .
cmake --build $BUILDDIR -j
cp $BUILDDIR/rosettaboy-cpp ./rosettaboy-release
8 changes: 8 additions & 0 deletions cpp/build_debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -eu

cd $(dirname $0)
BUILDDIR=build/debug/$(uname)-$(uname -m)
cmake -DCMAKE_BUILD_TYPE=Debug -B $BUILDDIR .
cmake --build $BUILDDIR -j
cp $BUILDDIR/rosettaboy-cpp ./rosettaboy-debug
1 change: 1 addition & 0 deletions nim/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
rosettaboy
bin.*
libSDL2.dylib
7 changes: 6 additions & 1 deletion nim/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ set -eu

cd $(dirname $0)
nimble --accept build -d:release
cp ./rosettaboy ./rosettaboy-release
mv ./rosettaboy ./bin.release
cat >rosettaboy-release <<EOD
#!/bin/sh
DYLD_LIBRARY_PATH=\$(dirname \$0) exec \$(dirname \$0)/bin.release \$*
EOD
chmod +x rosettaboy-release
11 changes: 11 additions & 0 deletions nim/build_debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -eu

cd $(dirname $0)
nimble --accept build -d:debug
mv ./rosettaboy ./bin.debug
cat >rosettaboy-debug <<EOD
#!/bin/sh
DYLD_LIBRARY_PATH=\$(dirname \$0) exec \$(dirname \$0)/bin.debug \$*
EOD
chmod +x rosettaboy-debug
7 changes: 6 additions & 1 deletion nim/build_speed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ export PATH="/Users/shish2k/homebrew/opt/llvm/bin:$PATH"

cd $(dirname $0)
nimble --accept build -d:danger --opt:speed -d:lto --mm:arc --panics:on
cp ./rosettaboy ./rosettaboy-speed
mv ./rosettaboy ./bin.speed
cat >rosettaboy-speed <<EOD
#!/bin/sh
DYLD_LIBRARY_PATH=\$(dirname \$0) exec \$(dirname \$0)/bin.speed \$*
EOD
chmod +x rosettaboy-speed
3 changes: 1 addition & 2 deletions php/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ cat >rosettaboy-release <<EOD
#!/usr/bin/env bash
set -eu
cd \$(dirname \$0)
if [ -f \${HOME}/php-sdl/modules/sdl.so ] ; then
FLAGS=-dextension=\${HOME}/php-sdl/modules/sdl.so
else
FLAGS=
fi
exec php \$FLAGS src/main.php \$*
exec php \$FLAGS "\$(dirname \$0)/src/main.php" \$*
EOD
chmod +x rosettaboy-release
3 changes: 1 addition & 2 deletions php/build_opcache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ cat >rosettaboy-opcache <<EOD
#!/usr/bin/env bash
set -eu
cd \$(dirname \$0)
if [ -f \${HOME}/php-sdl/modules/sdl.so ] ; then
FLAGS=-dextension=\${HOME}/php-sdl/modules/sdl.so
else
FLAGS=
fi
exec php \$FLAGS -dopcache.enable_cli=1 -dopcache.jit_buffer_size=100M src/main.php \$*
exec php \$FLAGS -dopcache.enable_cli=1 -dopcache.jit_buffer_size=100M "\$(dirname \$0)/src/main.php" \$*
EOD
chmod +x rosettaboy-opcache
5 changes: 2 additions & 3 deletions pxd/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ python3 setup.py build "$@" --build-base "$BUILD_DIR" --build-purelib "$BUILD_DI
cat >rosettaboy-release <<EOD
#!/usr/bin/env bash
set -eu
cd \$(dirname \$0)
source py_env.sh
exec python3 build/main.py \$*
source "\$(dirname \$0)/py_env.sh"
PYTHONPATH="\$(dirname \$0)/build/" exec python3 "\$(dirname \$0)/build/main.py" \$*
EOD
chmod +x rosettaboy-release
6 changes: 3 additions & 3 deletions py/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source py_env.sh
cat >rosettaboy-release <<EOD
#!/usr/bin/env bash
set -eu
cd \$(dirname \$0)
exec $(command -v python3) -c "from src.main import main ; import sys ; sys.exit(main(sys.argv))" \$*
source "\$(dirname \$0)/py_env.sh"
PYTHONPATH="\$(dirname \$0)" exec python3 -c "from src.main import main ; import sys ; sys.exit(main(sys.argv))" \$*
EOD
chmod +x rosettaboy-release
chmod +x rosettaboy-release
6 changes: 3 additions & 3 deletions py/build_mypyc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mypyc rbmp
cat >rosettaboy-mypyc <<EOD
#!/usr/bin/env bash
set -eu
cd \$(dirname \$0)
exec $(command -v python3) -c "from rbmp.main import main ; import sys ; sys.exit(main(sys.argv))" \$*
source "\$(dirname \$0)/py_env.sh"
PYTHONPATH="\$(dirname \$0)" exec python3 -c "from rbmp.main import main ; import sys ; sys.exit(main(sys.argv))" \$*
EOD
chmod +x rosettaboy-mypyc
chmod +x rosettaboy-mypyc
9 changes: 5 additions & 4 deletions py/py_env.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Instead of being run, this gets `source`d by `build.sh` and `format.sh`.

BUILDDIR=venv/$(uname)-$(uname -m)
PYIMPORT_EXIT=$(python3 -c 'import sdl2, black, mypy' 1>&2; echo $?) # Use existing libraries (E.G. from system, or from Nix) if found.
if [ $PYIMPORT_EXIT -eq 0 ] ; then
BUILDDIR=$(dirname $0)/venv/$(uname)-$(uname -m)

# Use existing libraries (E.G. from system, or from Nix) if found.
if python3 -c 'import sdl2, black, mypy' 2>/dev/null ; then
echo "Python packages found:"
python3 -c 'import sdl2, black, mypy; [print(module.__file__) for module in [sdl2, black, mypy]]'
else
if [ ! -d $BUILDDIR ] ; then
echo "Installing PySDL2, MyPy, and Black in $BUILDDIR"
python3 -m venv $BUILDDIR
$BUILDDIR/bin/pip install pysdl2 pysdl2-dll mypy black
$BUILDDIR/bin/pip install pysdl2 pysdl2-dll git+https://github.com/python/mypy.git black
fi
echo "Using Python3 in $BUILDDIR"
PATH="$BUILDDIR/bin:$PATH"
Expand Down
6 changes: 6 additions & 0 deletions rs/build_debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -eu

cd $(dirname $0)
cargo build
cp target/debug/rosettaboy-rs ./rosettaboy-debug
2 changes: 1 addition & 1 deletion rs/build_lto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eu

cd $(dirname $0)
cargo build --profile release-lto
cp ./target/release/rosettaboy-rs ./rosettaboy-lto
mv ./target/release-lto/rosettaboy-rs ./rosettaboy-lto
2 changes: 1 addition & 1 deletion zig/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eu

cd $(dirname $0)
zig build -Drelease-fast=true
cp ./zig-out/bin/rosettaboy ./rosettaboy-release
mv ./zig-out/bin/rosettaboy ./rosettaboy-release
2 changes: 1 addition & 1 deletion zig/build_safe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eu

cd $(dirname $0)
zig build -Drelease-safe=true
cp ./zig-out/bin/rosettaboy ./rosettaboy-safe
mv ./zig-out/bin/rosettaboy ./rosettaboy-safe

0 comments on commit 6a799e0

Please sign in to comment.