Skip to content

Absolute Paths not working with build-obj #3102

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

Closed
marler8997 opened this issue Aug 20, 2019 · 6 comments
Closed

Absolute Paths not working with build-obj #3102

marler8997 opened this issue Aug 20, 2019 · 6 comments

Comments

@marler8997
Copy link
Contributor

marler8997 commented Aug 20, 2019

Reproduce with:

$ touch foo.zig
$ zig build-obj --name /tmp/foo foo.zig
unable to write object file .//tmp/foo.o: No such file or directory

Zig is prefixing the --name argument with ./ for some reason?

@daurnimator
Copy link
Contributor

daurnimator commented Aug 20, 2019

it gets prefixed with the target directory. Note that name is used in a few places including e.g. the soname for a shared library.

I think you might have been looking for --output-dir rather than --name?

@marler8997
Copy link
Contributor Author

How would I direct the output file to /dev/null?

@marler8997
Copy link
Contributor Author

marler8997 commented Aug 20, 2019

It sounds like for my zigcc project, I probably just want to always set --output-dir to an empty string:

zig build-obj --output-dir "" --name <path> ...

That way the --name <path> option will work as expected. Does this sound right? Maybe if --output-dir is not explicitly given on the command-line, zig should just treat other path-names as if they are real path names? What do you think?

Or maybe if --name is an absolute path, then it wouldn't prefix it with output-dir?

Or another idea, I think in general it's quite confusing when path names passed to programs are treated as relative names to some other directory. In this case, it seems --name is treated as a path "suffix" to output-dir. Instead, maybe it should only be allowed to be a "basename" where it produces an error if it contains any slashes and/or backslashes. This would make it easy to realize that you must set --output-dir if you want to change the output path.

So I'm not sure what the right solution is here, but I think the current semantics are surprising and I'm still not sure how to correctly use these command-line options to get the results I want. Maybe more explanation on what these options are meant for would be helpful.

@andrewrk
Copy link
Member

--name is not a path. Feel free to propose for it to work differently, but this is a misunderstanding of the CLI.

@marler8997
Copy link
Contributor Author

marler8997 commented Aug 21, 2019

Yes I don't have a good grasp on the reasoning behind each command-line option. There doesn't seem to be a good source of documentation on it and it can be hard to understand the "spirit" behind each one from looking at the source.

Is one of you able to tell me how you would translate the -o option from C compilers to Zig? Would you set --output-dir to an empty string and then set the path to --name?

Also, should it be an error if --name contains slashes and/or backslashes then? Since it's not a path then would that be an error?

@andrewrk
Copy link
Member

Let's discuss over in #3089. That's what you're actually trying to do, right?

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

No branches or pull requests

3 participants