received command line args are empty when using --linker=legacy
$ ./target/release/roc run examples/args.roc --linker=legacy -- log -b 3 --num 81
args-example
A calculator example of the CLI platform argument parser
COMMANDS:
div
OPTIONS:
--dividend, -n the number to divide; corresponds to a numerator (integer, 64-bit signed)
--divisor, -d the number to divide by; corresponds to a denominator (integer, 64-bit signed)
log
OPTIONS:
--base, -b base of the logarithm (integer, 64-bit signed)
--num the number to take the logarithm of (integer, 64-bit signed)
The program name "args-example" was not provided as a first argument!
The weird thing is, this only happens when using a basic-cli release, not when building the platform from source.
We use the rust args_os function under the hood, in the docs it is mentioned that "The first element is traditionally the path of the executable, but it can be set to arbitrary text, and might not even exist. This means this property should not be relied upon for security purposes."
This does not happen without --linker=legacy. So far we've seen this on NixOS and Ubuntu.
On linux args_os uses the init_array section of the executable (assembly), this section does not exist in the executable created by the legacy linker.
I believe this happens because we target musl for the release build, you can workaround this by building locally:
git clone https://github.com/roc-lang/basic-cli.git
cd basic-cli
# adjust 0.10.0 to your desired version
git checkout tags/0.10.0
Change the platform in your roc file from:
app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}
To (adjust path for your basic-cli folder):
app [main] {
pf: platform "/home/username/gitfolders/basic-cli/platform/main.roc",
}
Build your app:
roc main.roc --linker=legacy
Now the platform is built, to prevent unnecessary rebuilding you can do:
roc main.roc --linker=legacy --prebuilt-platform
To pass args (e.g. fileA.txt and fileB.txt) the syntax is:
roc main.roc --linker=legacy --prebuilt-platform -- fileA.txt fileB.txt
The musl target was indeed the issue, this was fixed here and is available in rust 1.79, time to do some upgrading...
This still happens with the basic-cli 0.12.0 pre-release which was built using rust 1.79
This could possibly be what is going on: https://roc.zulipchat.com/#narrow/channel/302903-platform-development/topic/getting.20args.20when.20using.20.60roc.20run.60.3F/near/477689098
Note: once we figure out a fix for this there's a test in the roc compiler repo that we can un-ignore. See: https://github.com/roc-lang/roc/pull/7172
This is fixed in basic-cli 0.18.0 :tada: