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

target:set not working correctly for arch and toolchains #1135

Closed
s5bug opened this issue Dec 11, 2020 · 14 comments
Closed

target:set not working correctly for arch and toolchains #1135

s5bug opened this issue Dec 11, 2020 · 14 comments
Milestone

Comments

@s5bug
Copy link

s5bug commented Dec 11, 2020

Describe the bug

Create a ruleset like so:

-- create a default rule for matching compilation
rule("matching")
    on_load(function (target)
        -- Windows x86
        target:set("plat", "windows")
        target:set("arch", "x86")
    
        -- use MSVC and NASM
        target:set("toolchains", "msvc", "nasm")
        target:add("config", "as=nasm")
        
        -- use VS 2005
        target:add("config", "vs=2005")
        
        -- set Windows Vista as the minimum Windows version
        target:add("defines", "_WIN32_WINNT=0x0600")
        
        -- link necessary system libraries
        target:add("syslinks", "user32", "ole32")
        
        -- statically link the C Runtime
        if is_mode("debug") then
            target:add("cxflags", "/MTd")
        else
            target:add("cxflags", "/MT")
        end
    end)

Create a target that uses the ruleset:

target("foo")
    set_kind("binary")
    
    -- only matching builds for now
    add_rules("matching")
    
    -- include pstdint to make up for VS 2005 not having stdint.h
    add_includedirs(
        "external/pstdint/include"
    )
    
    -- platform-independent source files
    add_files(
        "asm/some_asm.asm",
        "src/main.cpp"
    )

Expected behavior

Running xmake from a clean directory should build properly, using NASM to build the assembly and VS 2005 to build the C++.

Error output

> xmake
checking for architecture ... x64
checking for Microsoft Visual Studio (x64) version ... 2005
checking for Microsoft Visual Studio (x86) version ... 2005
error: toolchain("clang"): not found!

Even though clang was not a desired toolchain.

Related Environment

Please provide compiling and running environment information:

  • xmake version: xmake v2.3.9+202012081639
  • os: Windows 10 Home 20H2 Build 19042.662
  • target platform: Win32 Vista

Additional context

Setting vs, arch, plat, and toolchain via xmake f has the following output:

> xmake f -p windows -a x86 --vs=2005 --toolchain=msvc --toolchain=nasm -m releasedbg
checking for Microsoft Visual Studio (x86) version ... 2005

Then an xmake builds the project successfully. Notice how it doesn't look for the x64 version of VS 2005.

@waruqi
Copy link
Member

waruqi commented Dec 11, 2020

oh, I need improve toolchain and rule. Please wait some time.

@waruqi
Copy link
Member

waruqi commented Dec 11, 2020

You can update to dev version and try it. (download dev installer from https://github.com/xmake-io/xmake/actions/runs/415756225 and need wait ci finished)

add_rules("mode.debug", "mode.release")
set_config("vs", "2005")

rule("matching")
    before_load(function (target)
        -- Windows x86
        target:set("arch", "x86")
        target:set("toolchains", "nasm", "msvc")

        -- set Windows Vista as the minimum Windows version
        target:add("defines", "_WIN32_WINNT=0x0600")

        -- link necessary system libraries
        target:add("syslinks", "user32", "ole32")

        -- statically link the C Runtime
        if is_mode("debug") then
            target:add("cxflags", "/MTd")
        else
            target:add("cxflags", "/MT")
        end
    end)

target("testvs")
    set_kind("binary")
    add_files("src/*.cpp", "src/*.asm")

    -- only matching builds for now
    add_rules("matching")
    target:set("toolchains", "nasm", "msvc")

We need to add the nasm toolchain first to override msvc (as) program.

set_config("vs", "2005")

Currently, we only support global setting vs version, maybe I will improve it later.

@waruqi
Copy link
Member

waruqi commented Dec 11, 2020

xmake f -p windows -a x86 --vs=2005 --toolchain=msvc --toolchain=nasm -m releasedbg

The command line parameter currently only supports one --toolchain, and the default platform is windows, and the default toolchain is msvc. We don't need to set it additionally.

@s5bug
Copy link
Author

s5bug commented Dec 11, 2020

Currently, we only support global setting vs version, maybe I will improve it later.

Can this be dynamic with some sort of config option?

@waruqi
Copy link
Member

waruqi commented Dec 11, 2020

Currently, we only support global setting vs version, maybe I will improve it later.

Can this be dynamic with some sort of config option?

?

@s5bug
Copy link
Author

s5bug commented Dec 11, 2020

For now, can I use some sort of option() to set the VS version? It's fine if it's set globally.

@waruqi
Copy link
Member

waruqi commented Dec 12, 2020

For now, can I use some sort of option() to set the VS version? It's fine if it's set globally.

Currently set_config does not support option, I need to improve set_toolchains to support vs version setting.

@waruqi
Copy link
Member

waruqi commented Dec 13, 2020

I am improving toolchain to better support the configuration vs version.

@waruqi
Copy link
Member

waruqi commented Dec 14, 2020

I have supported to set vs version on toochain branch. You can try it again.

Please update to toolchain branch.

xmake update -s toolchain

try this:

rule("matching")
    before_load(function (target)
        target:set("toolchains", "nasm", "msvc", {vs = 2015})
    end

I will merge this patch to dev branch if it works.

@waruqi
Copy link
Member

waruqi commented Dec 16, 2020

I continue to improve toolchain branch. you can try it again.

@waruqi
Copy link
Member

waruqi commented Dec 17, 2020

I have merged into dev branch.

@s5bug
Copy link
Author

s5bug commented Dec 27, 2020

Alright. Sorry for the late response, I've been incredibly busy:

-- add the default rules for the different compilation modes
add_rules("mode.debug", "mode.release", "mode.releasedbg")

-- create a default rule for matching compilation
rule("matching")
    before_load(function (target)
        -- Windows x86
        target:set("plat", "windows")
        target:set("arch", "x86")
    
        -- use MSVC 2005 and NASM
        target:set("toolchains", "nasm", "msvc", {vs = 2005})
        
        -- set Windows Vista as the minimum Windows version
        target:add("defines", "_WIN32_WINNT=0x0600")
        
        -- link necessary system libraries
        target:add("syslinks", "user32", "ole32")
        
        -- statically link the C Runtime
        if is_mode("debug") then
            target:add("cxflags", "/MTd")
        else
            target:add("cxflags", "/MT")
        end
    end)

target("LEGOStarWarsSaga")
    set_kind("binary")
    
    -- only matching builds for now
    add_rules("matching")

This creates the output:

> xmake
checking for platform ... windows
checking for architecture ... x64
checking for Microsoft Visual Studio (x64) version ... 2019
checking for Microsoft Visual Studio (x86) version ... 2019

So, it doesn't even look for VS2005.

It breaks on xmake -f:

> xmake f --vs=2005
checking for platform ... windows
checking for architecture ... x64
checking for Microsoft Visual Studio (x64) version ... 2005
checking for Microsoft Visual Studio (x86) version ... 2019

@waruqi waruqi reopened this Dec 27, 2020
@waruqi
Copy link
Member

waruqi commented Dec 27, 2020

    target:set("toolchains", "nasm", "msvc", {vs = 2005})

my mistake, try string {vs = "2005"}

@s5bug
Copy link
Author

s5bug commented Dec 27, 2020

target:set("toolchains", "nasm", "msvc", {vs = "2005"}): wrap the version in quotes and it works perfectly.

> xmake
checking for platform ... windows
checking for architecture ... x64
checking for Microsoft Visual Studio (x64) version ... 2019
checking for Microsoft Visual Studio (x86) version ... 2005

@waruqi waruqi closed this as completed Dec 27, 2020
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