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

Order of Toolchain Flags and User Flags in Compilation Process #978

Closed
RoyiAvital opened this issue Oct 3, 2020 · 13 comments
Closed

Order of Toolchain Flags and User Flags in Compilation Process #978

RoyiAvital opened this issue Oct 3, 2020 · 13 comments

Comments

@RoyiAvital
Copy link

RoyiAvital commented Oct 3, 2020

At the moment, according to Gitter talk:

the built-in toolchain flags are placed last by default.

I think this policy, for the compilation process should be changed. The order should be user flags (By add_cflags() or set_cflags() and their extension to other languages) are the last.

The logic is that in most (All?) compilers the last flags are the one to override preceding ones.
Hence it means the user will be able to set the flags one wants and override defaults.

An example is using the 32 Bit Pointers math in 64 bit mode under MinGW for x64.
The user cat set add_cxflags("-mx32"), namely the user wants to use 32 Bit pointers in 64 Bit programs. Yet since -m64 as the default toolchain flag will be last it will override the user flags.

@waruqi
Copy link
Member

waruqi commented Oct 4, 2020

The logic is that in most (All?) compilers the last flags are the one to override preceding ones.

Not exactly, -Isys_dir -Iuser_dir will not overwrite, but the search order of header files is reversed. If so, system header files with the same name will be found first.

@RoyiAvital
Copy link
Author

I am talking about compilations flags, not commands. Compilation in the meaning they change the output of the compilation and not what's getting in.

@waruqi
Copy link
Member

waruqi commented Oct 4, 2020

? What I’m also talking about is compilation flags (-Isys_dir -Iuser_dir), and -Isys_dir is a built-in compilation flag of the toolchain. If we put all the toolchain flags (contain -m64) at the beginning, then some -Isys_dir compilation flags of toolchain will also be affected.

@RoyiAvital
Copy link
Author

RoyiAvital commented Oct 4, 2020

I think compilation flags should be separated into:

  1. Search Paths (Folders, libraries).
  2. Objects (Object files, Static Library Files).
  3. Compilation Flags (What changes the output of the compiler given a code, the others do not, they just change the input for the compilation process).

On top of that we have complication definition and input files.

Compilation Flags are the defaults of xmake + User Flags. Their order should be xmake default flags and then user flags.

@waruqi
Copy link
Member

waruqi commented Oct 6, 2020

I will try to improve the order, but the search path is also part of the compiled flags, and there is currently no way to separate them.

@RoyiAvital
Copy link
Author

RoyiAvital commented Oct 6, 2020

When you say no way to separate them you mean in the current code of xmake?
As this is not a limitation of the toolchain.

Rethinking it, I think a better partition would be:

  1. Compiler Options
    • Search paths (Object files, Static Library Files [Actually for linking]).
    • Compilation definitions.
  2. Compiler Input
    • RAW text files (For instance, .c / .cpp).
    • Object files (Actually for linking).
  3. Compilation Flags (What changes the output of the compiler given a code, the others do not, they just change the input for the compilation process).

I think xmake code should use this model and then just separate compilation flags by user or by default.

@waruqi
Copy link
Member

waruqi commented Oct 6, 2020

I have improved their order and separated compilation flags and seachdirs/links. You can update to the dev version and try it again.

@waruqi
Copy link
Member

waruqi commented Oct 7, 2020

Dose it work? I have improved it.

@RoyiAvital
Copy link
Author

Is it also on the build form the CI?

@waruqi
Copy link
Member

waruqi commented Oct 7, 2020

we can also only update lua scripts.

xmake update -s dev

@RoyiAvital
Copy link
Author

I will wait for a fix for #977 (comment) and will check them both at once.

@RoyiAvital
Copy link
Author

Tested it and on the few examples I ran indeed the user flags were after the default flags.
Though the include libraries were in between which I think is wrong.

Any chance for <default flags> <user flags> <include libraries>?

@waruqi
Copy link
Member

waruqi commented Oct 8, 2020

<default toolchain flags> <user flags and include libraries> <default toolchain include libraries> now

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

No branches or pull requests

2 participants