Skip to content

Conversation

@aykevl
Copy link
Member

@aykevl aykevl commented Sep 25, 2020

This has been a long requested feature.

fixes #456 and #541

example usage:

package main

import "os"

func main() {
	println("num args:", len(os.Args))
	for _, arg := range os.Args {
		println("arg:", arg)
	}
}
$ tinygo build -o args ./args.go
$ ./args hello world
num args: 3
arg: ./args
arg: hello
arg: world

@bgould
Copy link
Member

bgould commented Sep 25, 2020

This is an exciting new feature, and looks good to me. Do you think that we should have any tests for this functionality?

@deadprogram
Copy link
Member

Agreed with @bgould this is very exciting! Also agree that some test coverage would be a very good idea.

@deadprogram
Copy link
Member

@aykevl can you please both handle the merge conflict, and also consider adding a unit test? Thank you.

@deadprogram
Copy link
Member

Reminder to @aykevl to please resolve and merge conflict, and consider adding unit test. Thanks.

This simplifies the code somewhat but more importantly makes it possible
to put other tests under testdata.
@aykevl
Copy link
Member Author

aykevl commented Oct 23, 2020

I have gotten it working, but somehow this change causes a segmentation fault when I run the stdlib test. The issue seems to be in the interp package where somehow an unaligned memory location is loaded from.

I plan to finish this PR after #1430 is finished and merged, as that PR should avoid this issue (hopefully).

That said, this PR is now rebased to fix the conflicts and has a test (which is indeed a good idea). I made the test in such a way that it should be easy to add environment variables in the future, which I assume will come up soon enough.

@arp242
Copy link
Contributor

arp242 commented Oct 23, 2020

I was looking at this yesterday – as I'm kind of waiting on it – and it segfaults when you try to import the os package; this doesn't just happen from the tests, it also happens when you run a program compiled with this change. I couldn't really figure out the cause though 😅

@aykevl
Copy link
Member Author

aykevl commented Oct 24, 2020

Yeah I haven't found the root cause yet. It seems to be related to the interp package and/or the way globals are packed into one giant global to make them scannable by the GC, and it might just be a LLVM compiler bug even. Either I can look for that, or maybe just give up on that and work on the new interp package instead (which should sidestep this problem entirely).

@jfcg
Copy link

jfcg commented Jan 19, 2021

would be great to have os.Args, really fundamental stuff. i want to try on some tools with tinygo.
thanks..

@hanabi1224
Copy link

Looking forward to having this!

@aykevl
Copy link
Member Author

aykevl commented Apr 16, 2021

Closed in favor of #1812.

@aykevl
Copy link
Member Author

aykevl commented Aug 15, 2021

Now actually closing.

@aykevl aykevl closed this Aug 15, 2021
@aykevl aykevl deleted the runtime-cmdline branch August 15, 2021 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants