Repository navigation
Description
What you did
Built a program that prints its arguments, then ran it with arguments a typical command-line tool receives:
bend args.bend -o args && ./args grep -e --threads notes.txt
What happened
The runtime takes --threads, --gpu, --gpu-build and the first -- from anywhere in the program's argv, including where they are the values of the program's own options:
$ ./args grep -e --threads notes.txt
bend: expected a thread count of 1 or more after --threads # exit 1; main never runs
$ ./args compress --threads auto
bend: expected a thread count of 1 or more after --threads # exit 1
$ ./args build --threads 4
[<./args>, <build>]
$ ./args fetch --gpu off
[<./args>, <fetch>]
$ ./args make --gpu-build # exit 0; main never runs
$ ./args grep -- -v
[<./args>, <grep>, <-v>] # the program never sees --
$ ./args grep -- -- -v
[<./args>, <grep>, <-->, <-v>]
$ bun args.js build --threads 4
[<…/args.js>, <build>]
So a compiled program cannot:
- take an option named
--threadsor--gpu; - accept either word as an option's value (
grep -e --threads) without the runtime failing beforemainruns; - see
--, so POSIX end-of-options handling costs its users-- --.
--threads matters most. It is the conventional name of the option that parallel tools expose: ripgrep -j, --threads, xz -T, --threads, zstd -T, --threads. A Bend program can read its worker count (IO.thread_count, #971), but it cannot offer the flag its users expect.
#934 moved the runtime's --help to --bend-help. This asks to finish that change for the remaining options.
Request
IO.args()in a compiled program, native or JS, is exactly its argv, after the program name.- Runtime settings come from the environment, read once at startup:
BEND_THREADS=8,BEND_GPU=off|on|4GB. Bad values fail as they do today. Prior art:GOMAXPROCS,RAYON_NUM_THREADS,OMP_NUM_THREADS. GHC made the same change in 7.0: compiled programs stopped accepting most+RTSoptions unless linked with-rtsopts. --gpu-buildand--bend-helpmove tobenditself (bend main.bend -o main --gpu-build) or to the environment (BEND_GPU_BUILD=1 ./main).- Optional: a build-time default,
bend main.bend -o main --threads 8.
Migration: ./main --threads 8 becomes BEND_THREADS=8 ./main. This touches the GUIDE's Tooling block, CLI_HELP and the C main in comp.ts, cli() in comp.ts, tests/io/args.bend, and FLAGS in gates/perf.ts. I'm happy to send the patch if this direction is acceptable.
The file
import Base
def main() -> IO(Unit):
do IO<Unit>:
xs : List<String> <- IO.args()
IO.print(List.show(~&1, ~String, ~(s => "<" ++ s ++ ">"), xs))bend --version
bend 2.0.36
uname -sm
Darwin arm64
clang --version (the first line)
Apple clang version 21.0.0 (clang-2100.1.1.101)
Activity
fix(runtime)!: runtime options go between +RTS and -RTS, as in GHC (b…
Note that 1.0 waits on Bend's runtime argv fix
fix(runtime)!: runtime options go between +RTS and -RTS (#1466) (#1530)
Bring AGENTS.md up to date with the work since its tools landed
Require Bend 2.0.38