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

automatic linker detection #71

Closed
TitanSnow opened this Issue Apr 12, 2017 · 21 comments

Comments

Projects
None yet
2 participants
@TitanSnow
Contributor

TitanSnow commented Apr 12, 2017

travis ci log

In short, when environment var $CXX==clang++ (build with clang++ on travis-ci), xmake uses clang++ to compile but g++ to link.

In common situation, it will not cause problems. But it fails when compiling with code coverage (flag -coverage).

By the way, is there a easy way in xmake to compile with code coverage?

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 12, 2017

Member

You need set environment var $LD==clang++ at the same time if you modified var $CXX==clang++ .

And you can write a mode named coverage in xmake.lua:

if is_mode("coverage") then
    add_cxflags("--coverage")
    add_ldflags("--coverage")
end

Then run:

$ xmake f -m coverage
$ xmake
Member

waruqi commented Apr 12, 2017

You need set environment var $LD==clang++ at the same time if you modified var $CXX==clang++ .

And you can write a mode named coverage in xmake.lua:

if is_mode("coverage") then
    add_cxflags("--coverage")
    add_ldflags("--coverage")
end

Then run:

$ xmake f -m coverage
$ xmake

@waruqi waruqi added the discussion label Apr 12, 2017

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 12, 2017

Contributor

Sounds right. So you mean travis-ci does wrong with environment var setting?

Contributor

TitanSnow commented Apr 12, 2017

Sounds right. So you mean travis-ci does wrong with environment var setting?

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 12, 2017

Contributor

By the way, is -coverage cross-platform? Will xmake set it smartly?

Contributor

TitanSnow commented Apr 12, 2017

By the way, is -coverage cross-platform? Will xmake set it smartly?

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 12, 2017

Member

travis-ci only modify $CXX and did not tell xmake which linker to choose, so xmake will use the default linker if cannot get $(LD).

I'm sorry, xmake do not support to adjust the linker's detection order automatically according to $CXX now. I will improve it in the future.

You can modify travis-ci setting to export LD=clang++ now.

Member

waruqi commented Apr 12, 2017

travis-ci only modify $CXX and did not tell xmake which linker to choose, so xmake will use the default linker if cannot get $(LD).

I'm sorry, xmake do not support to adjust the linker's detection order automatically according to $CXX now. I will improve it in the future.

You can modify travis-ci setting to export LD=clang++ now.

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 12, 2017

Member

How do you need to set it smartly? You can call add_cxflags("-coverage") to set it directly. If some compilers do not support this flags, xmake will check and ignore it.

Member

waruqi commented Apr 12, 2017

How do you need to set it smartly? You can call add_cxflags("-coverage") to set it directly. If some compilers do not support this flags, xmake will check and ignore it.

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 12, 2017

Contributor

What I mean is that sometimes just simply ignore flags not supported sounds not fantastic enough. I found you map -fomit-frame-pointer to -Oy on VS

Contributor

TitanSnow commented Apr 12, 2017

What I mean is that sometimes just simply ignore flags not supported sounds not fantastic enough. I found you map -fomit-frame-pointer to -Oy on VS

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 12, 2017

Member

xmake support to map flags to other compilers. (.e.g vs, ..) you can see https://github.com/tboox/xmake/blob/master/xmake/tools/cl.lua

xmake takes the gcc flags as the standard and will map to other compiler flags smartly.

you can help me to contribute some patches to the following mapflags if the flags you need does not provide a mapping yet.

    _g.mapflags = 
    {
        -- optimize
        ["-O0"]                     = "-Od"
    ,   ["-O3"]                     = "-Ot"
    ,   ["-Ofast"]                  = "-Ox"
    ,   ["-fomit-frame-pointer"]    = "-Oy"
    ,   ["-g"]                      = "-Z7"
    ,   ["-fvisibility=.*"]         = ""

Thanks!

Member

waruqi commented Apr 12, 2017

xmake support to map flags to other compilers. (.e.g vs, ..) you can see https://github.com/tboox/xmake/blob/master/xmake/tools/cl.lua

xmake takes the gcc flags as the standard and will map to other compiler flags smartly.

you can help me to contribute some patches to the following mapflags if the flags you need does not provide a mapping yet.

    _g.mapflags = 
    {
        -- optimize
        ["-O0"]                     = "-Od"
    ,   ["-O3"]                     = "-Ot"
    ,   ["-Ofast"]                  = "-Ox"
    ,   ["-fomit-frame-pointer"]    = "-Oy"
    ,   ["-g"]                      = "-Z7"
    ,   ["-fvisibility=.*"]         = ""

Thanks!

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 12, 2017

Contributor

I see 😸

Contributor

TitanSnow commented Apr 12, 2017

I see 😸

@TitanSnow TitanSnow changed the title from build with coverage fails to automatic linker detection Apr 12, 2017

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 12, 2017

Contributor

update title to "automatic linker detection"

Contributor

TitanSnow commented Apr 12, 2017

update title to "automatic linker detection"

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 12, 2017

Contributor

I have looked up in msdn. I think optimize flags should be mapped as this:

diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua
index 6888199..07a1b98 100644
--- a/xmake/tools/cl.lua
+++ b/xmake/tools/cl.lua
@@ -42,8 +42,10 @@ function init(shellname, kind)
     {
         -- optimize
         ["-O0"]                     = "-Od"
-    ,   ["-O3"]                     = "-Ot"
-    ,   ["-Ofast"]                  = "-Ox"
+    ,   ["-O1"]                     = ""
+    ,   ["-Os"]                     = "-O1"
+    ,   ["-O3"]                     = "-Ox"
+    ,   ["-Ofast"]                  = "-Ox -fp:fast"
     ,   ["-fomit-frame-pointer"]    = "-Oy"
 
         -- symbols

/O Options (Optimize Code) - msdn

Contributor

TitanSnow commented Apr 12, 2017

I have looked up in msdn. I think optimize flags should be mapped as this:

diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua
index 6888199..07a1b98 100644
--- a/xmake/tools/cl.lua
+++ b/xmake/tools/cl.lua
@@ -42,8 +42,10 @@ function init(shellname, kind)
     {
         -- optimize
         ["-O0"]                     = "-Od"
-    ,   ["-O3"]                     = "-Ot"
-    ,   ["-Ofast"]                  = "-Ox"
+    ,   ["-O1"]                     = ""
+    ,   ["-Os"]                     = "-O1"
+    ,   ["-O3"]                     = "-Ox"
+    ,   ["-Ofast"]                  = "-Ox -fp:fast"
     ,   ["-fomit-frame-pointer"]    = "-Oy"
 
         -- symbols

/O Options (Optimize Code) - msdn

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 12, 2017

Member

vc support -Os flags directly, why should change mapping -Os to -O1? Is vc's-Os not equivalent to gcc's -Os?

  • /Os tells the compiler to favor optimizations for size over optimizations for speed.
Member

waruqi commented Apr 12, 2017

vc support -Os flags directly, why should change mapping -Os to -O1? Is vc's-Os not equivalent to gcc's -Os?

  • /Os tells the compiler to favor optimizations for size over optimizations for speed.
@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 12, 2017

Contributor

-Os is a subset of -O1

/O1 (Minimize Size) Equivalent to /Og /Os /Oy /Ob2 /Gs /GF /Gy

And there it says:

If you use /Os or /Ot, then you must also specify /Og to optimize the code.

I think the document is trying to let us consider /O1 /O2 /Ox first. They're sets of flags that works well.

"Favor" means just a note telling to compiler setting the optimize kind but do not actually do something.

Contributor

TitanSnow commented Apr 12, 2017

-Os is a subset of -O1

/O1 (Minimize Size) Equivalent to /Og /Os /Oy /Ob2 /Gs /GF /Gy

And there it says:

If you use /Os or /Ot, then you must also specify /Og to optimize the code.

I think the document is trying to let us consider /O1 /O2 /Ox first. They're sets of flags that works well.

"Favor" means just a note telling to compiler setting the optimize kind but do not actually do something.

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 12, 2017

Member

👍 I got it. Can you submit a patch to dev branch? I will merge it, thanks!

Member

waruqi commented Apr 12, 2017

👍 I got it. Can you submit a patch to dev branch? I will merge it, thanks!

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 12, 2017

Contributor

But I haven't tested it yet because I don't have Windows. 😿

Could you do a quickly test to know if it could work?

Contributor

TitanSnow commented Apr 12, 2017

But I haven't tested it yet because I don't have Windows. 😿

Could you do a quickly test to know if it could work?

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 12, 2017

Member

Ok, I will test it.

Member

waruqi commented Apr 12, 2017

Ok, I will test it.

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 12, 2017

Member

I have committed this patch.

Member

waruqi commented Apr 12, 2017

I have committed this patch.

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow Apr 12, 2017

Contributor

😺 Sorry for trouble

Contributor

TitanSnow commented Apr 12, 2017

😺 Sorry for trouble

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 12, 2017

Member

That's nothing. 😄

Member

waruqi commented Apr 12, 2017

That's nothing. 😄

@TitanSnow

This comment has been minimized.

Show comment
Hide comment
@TitanSnow

TitanSnow May 19, 2017

Contributor

@waruqi Could give a milestone? I found automatic linker detection is important in some situation

Contributor

TitanSnow commented May 19, 2017

@waruqi Could give a milestone? I found automatic linker detection is important in some situation

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi May 19, 2017

Member

@TitanSnow Yes, I'll improve and support it in the future, but it will take some time.

Member

waruqi commented May 19, 2017

@TitanSnow Yes, I'll improve and support it in the future, but it will take some time.

@waruqi waruqi modified the milestones: detection, v2.1.5 Jun 3, 2017

waruqi referenced this issue Jun 19, 2017

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Jun 20, 2017

Member

@TitanSnow

In short, when environment var $CXX==clang++ (build with clang++ on travis-ci), xmake uses clang++ to compile but g++ to link.

I have fixed it in dev branch.

Member

waruqi commented Jun 20, 2017

@TitanSnow

In short, when environment var $CXX==clang++ (build with clang++ on travis-ci), xmake uses clang++ to compile but g++ to link.

I have fixed it in dev branch.

@TitanSnow TitanSnow closed this Jun 28, 2017

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