Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

received command line args are empty when using --linker=legacy #82

Open
Anton-4 opened this issue Jul 5, 2023 · 7 comments · Fixed by #216
Open

received command line args are empty when using --linker=legacy #82

Anton-4 opened this issue Jul 5, 2023 · 7 comments · Fixed by #216

Comments

@Anton-4
Copy link
Collaborator

Anton-4 commented Jul 5, 2023

$ ./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."

@Anton-4 Anton-4 changed the title "args-example" was not provided as a first argument received command line args are empty Jun 15, 2024
@Anton-4
Copy link
Collaborator Author

Anton-4 commented Jun 15, 2024

This does not happen without --linker=legacy. So far we've seen this on NixOS and Ubuntu.

@Anton-4
Copy link
Collaborator Author

Anton-4 commented Jun 15, 2024

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.

@Anton-4
Copy link
Collaborator Author

Anton-4 commented Jun 15, 2024

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

@Anton-4
Copy link
Collaborator Author

Anton-4 commented Jun 18, 2024

The musl target was indeed the issue, this was fixed here and is available in rust 1.79, time to do some upgrading...

@Anton-4
Copy link
Collaborator Author

Anton-4 commented Jul 2, 2024

This still happens with the basic-cli 0.12.0 pre-release which was built using rust 1.79

@Anton-4 Anton-4 reopened this Jul 2, 2024
@Anton-4 Anton-4 changed the title received command line args are empty received command line args are empty when using --linker=legacy Jul 27, 2024
@Anton-4
Copy link
Collaborator Author

Anton-4 commented Oct 18, 2024

@jwoudenberg
Copy link

Note: once we figure out a fix for this there's a test in the roc compiler repo that we can un-ignore.
See: roc-lang/roc#7172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants