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

-dump-c-flags does not respect -o option #21824

Closed
thomas-mangin opened this issue Jul 8, 2024 · 7 comments
Closed

-dump-c-flags does not respect -o option #21824

thomas-mangin opened this issue Jul 8, 2024 · 7 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@thomas-mangin
Copy link
Contributor

thomas-mangin commented Jul 8, 2024

Describe the bug

When using both -dump-c-flags and the -o option, the file is well created in the current folder but the compilation_flags.rsp file reference what would have been the temporary location of the C file, not the one specified by -o.

Reproduction Steps

❯ v -cc gcc -dump-c-flags compilation_flags.rsp -keepc -o test.c test.v
❯ cat compilation_flags.rsp 
-fwrapv
-o "/Users/thomas/Code/github.com/ze-community/ze/main/test"
-D GC_BUILTIN_ATOMIC=1
-D MPROTECT_VDB=1
-D GC_THREADS=1
-I "/Users/thomas/Unix/local/v/master/thirdparty/libgc/include"
-x objective-c
"/private/tmp/v_501/test.tmp.c"
-x none
-std=c99
-D_DEFAULT_SOURCE
"/Users/thomas/Unix/local/v/master/thirdparty/tcc/lib/libgc.a"
-ldl
-lpthread

Expected Behavior

the generated compilation_flags.rsp has the right path for the file

Current Behavior

the file is generated in the tmp location

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.6 4475759

Environment details (OS name and version, etc.)

V full version: V 0.4.6 cc14272.4475759
OS: macos, macOS, 14.5, 23F79
Processor: 10 cpus, 64bit, little endian, Apple M1 Max

getwd: /Users/thomas/Code/github.com/ze-community/ze/main
vexe: /Users/thomas/Unix/local/v/master/v
vexe mtime: 2024-07-06 14:05:43

vroot: OK, value: /Users/thomas/Unix/local/v/master
VMODULES: OK, value: /Users/thomas/Unix/data/v/modules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.45.2
Git vroot status: weekly.2024.27-25-g4475759c (5 commit(s) behind V master)
.git/config present: true

CC version: Apple clang version 15.0.0 (clang-1500.3.9.4)
thirdparty/tcc status: thirdparty-macos-arm64 5c1d002f

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@thomas-mangin thomas-mangin added the Bug This tag is applied to issues which reports bugs. label Jul 8, 2024
@spytheman
Copy link
Member

It does have the right flags. V always stores temporary files in the VTMP folder.

What -o x.c does, is move the generated .tmp.c file later, to its final location.
It also skips starting the C compiler.

-dump-c-flags has nothing to do with it, and it does work as it should, by storing the original flags that were going to be used.

@thomas-mangin
Copy link
Contributor Author

@spytheman Thank you very much for such a quick answer.

I accept that the current behaviour accurately reflects the actions performed by V, and that altering the output could lead to a misinterpretation of the process, potentially causing other user issues.
I also note that users can easily edit the generated compiler file to change the C file location. Therefore, I have no objections to this closure and accept the current behaviour.

... That said, it is still not what a user without an understanding of the V internals would expect to see. When -o is used, the user probably intends to do "something" with the generated C code. Otherwise, they would not bother using the option, so it would have made sense for the generated compile command to reflect what they wanted to do.

I am surprised by this decision but accept that it would take time, perhaps best spent elsewhere.

Thank you for clarifying your position.

@medvednikov
Copy link
Member

@thomas-mangin does clang or gcc have similar flags which respect -o ?

@thomas-mangin
Copy link
Contributor Author

Hello @medvednikov - Thank you for joining this thread. I thought it closed after my last post.

I am sorry as I do not know the answer, nor do I understand why you asked the question.
Could you please help me understand your line of thinking please?

@medvednikov
Copy link
Member

GitHub allows having a discussion in closed threads.

If clang or gcc have this behavior (-o applying to not only binary path), then we should mimic it and implement this. Then this thread will be re-opened.

@thomas-mangin
Copy link
Contributor Author

Yes, we can continue this discussion. By closed, I thought the matter was closed :-)

For your point about matching GCC, I do not know enough about either GCC without a thorough investigation to answer meaningfully.

All I know is that:

  • -o binary is how the V handles generating its binary file.
  • -keepc -o file.c is how V handles generating the C file from the V code.

I was surprised to see -o used that way: When I first used V, I initially expected -keepc file.c -o binary as UI. As it stands, the two options are mutually exclusive in a single command.

It may be that -c file.c -o binary could be a way, but this was not your question. I will let you decide what you feel is best for V. It is your language and compiler toolchain, not mine.

I was only wondering if -dump-c-flags used with -keepc should save the flags that could be used to compile the generated C file instead of the flags used to compile the tmp file.

If the file is moved after the code generation, then the compiler options point to a missing file and will not allow the user to modify the C file and compile using the settings as they are.

It seems counterintuitive, but again, I am only giving my opinion as a user, nothing more.

@medvednikov
Copy link
Member

-o file.c works without -keepc

I'll investigate this and get back to you soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

3 participants