Skip to content

Clib integration (xmake-io/xmake#397) - #398

Merged
waruqi merged 11 commits into
xmake-io:devfrom
RaZeR-RBI:feature/clib-integration
Apr 15, 2019
Merged

waruqi merged 11 commits into
xmake-io:devfrom
RaZeR-RBI:feature/clib-integration

Conversation

@RaZeR-RBI

@RaZeR-RBI RaZeR-RBI commented Apr 14, 2019 •

Copy link
Copy Markdown
Contributor

Here is my implementation for #397.

Usage example

xmake.lua

add_requires("clib::clibs/bytes@0.0.4")

-- add modes: debug and release 
add_rules("mode.debug", "mode.release")

-- add target
target("xmake-test")

    -- set kind
    set_kind("binary")

    -- add files
    add_includedirs("clib")
    add_files("clib/bytes/*.c")
    add_files("src/*.c") 
    add_packages("clib::clibs/bytes")

src/main.c

#include <bytes/bytes.h>
#include <stdio.h>

int main(int argc, char** argv)
{
    char* kb = "640kb";
    long long kb_bytes = string_to_bytes(kb);
    printf("%s is %d bytes and ought to be enough for everyone\n", kb, kb_bytes);
    return 0;
}

Package detection is implemented by placing 'marker files' which have the same name as the package (but escaped, of course) and their content is a path to installation directory (defaults to 'clib' in project directory).

Looking forward to your answer 😉

@RaZeR-RBI RaZeR-RBI changed the title Clib integration (xmake-io/xmake#397) [WIP: Do not merge] Clib integration (xmake-io/xmake#397) Apr 14, 2019
@RaZeR-RBI

Copy link
Copy Markdown
Contributor Author

@waruqi Seems like I'm stuck. Is there a way to pass custom options to add_requires? Something like that:
add_requires("clib::clibs/bytes@0.0.4", {options={out_dir="my_deps", save=true}})

Other than that, installation using default options seems fine to me (for some reason it doesn't add includedirs to gcc flags though as I've thought before, but I'm fine with adding them manually in xmake.lua).

@waruqi

waruqi commented Apr 14, 2019

Copy link
Copy Markdown
Member

@waruqi Seems like I'm stuck. Is there a way to pass custom options to add_requires? Something like that:
add_requires("clib::clibs/bytes@0.0.4", {options={out_dir="my_deps", save=true}})

You can see

-- get configurations
function configurations()
return
{
build = {description = "use it to choose if you want to build from sources.", default = "missing", values = {"all", "never", "missing", "outdated"}},
remote = {description = "Set the conan remote server."},
options = {description = "Set the options values, e.g. OpenSSL:shared=True"},
imports = {description = "Set the imports for conan."},
settings = {description = "Set the build settings for conan."},
build_requires = {description = "Set the build requires for conan.", default = "xmake_generator/0.1.0@bincrafters/testing"}
}
end

And we can get these options in main(, opt) argument.

for _, setting in ipairs(opt.settings) do
table.insert(argv, "-s")
table.insert(argv, setting)
end
-- set remote
if opt.remote then
table.insert(argv, "-r")

Then we can pass custom options to install_package.lua

add_requires("clib::clibs/bytes@0.0.4", {configs={out_dir="my_deps", save=true}})

Other than that, installation using default options seems fine to me (for some reason it doesn't add includedirs to gcc flags though as I've thought before, but I'm fine with adding them manually in xmake.lua).

We can defines some default option value and uses values={} to constraint option value range.

build = {description = "use it to choose if you want to build from sources.", default = "missing", values = {"all", "never", "missing", "outdated"}},

        build          = {description = "...", default = "missing", values = {"all", "never", "missing", "outdated"}},
        build_requires = {description = "...", default = "xmake_generator/0.1.0@bincrafters/testing"}

@waruqi

waruqi commented Apr 14, 2019

Copy link
Copy Markdown
Member

Some examples for conan package:

add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true, 
    configs = {build_requires = "xmake_generator/0.1.0@bincrafters/testing", build = "all"}})

add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", 
    configs = {build_requires = "xmake_generator/0.1.0@bincrafters/testing",
    options = "OpenSSL:shared=True", build = "all"}})

target("test")
    set_kind("binary")
    add_files("src/*.c") 
    add_packages("openssl", "zlib")
add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}})
add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", 
    configs = {options = "OpenSSL:shared=True"}})

target("test")
    set_kind("binary")
    add_files("src/*.c") 
    add_packages("openssl", "zlib")

You can refer to #327 (Integrate with Conan package manager)

Comment thread xmake/core/sandbox/modules/io.lua Resolved
… into feature/clib-integration

Conflicts:
	xmake/modules/package/manager/clib/find_package.lua
	xmake/modules/package/manager/clib/install_package.lua
@RaZeR-RBI

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and help @waruqi 😁 I've fixed the issues and now everything works as intended (I've tested configuration flags too). Can we merge it?

@RaZeR-RBI RaZeR-RBI changed the title [WIP: Do not merge] Clib integration (xmake-io/xmake#397) Clib integration (xmake-io/xmake#397) Apr 15, 2019
@waruqi

waruqi commented Apr 15, 2019 •

Copy link
Copy Markdown
Member

By the way, which platform tests have you passed? Can you write a simple example of xmake.lua for clib here? Thanks!

@RaZeR-RBI

RaZeR-RBI commented Apr 15, 2019 •

Copy link
Copy Markdown
Contributor Author

By the way, which platform tests have you passed? Can you write a simple example of xmake.lua for clib here? Thanks!

I've tested it only on Linux (Debian 8 x64), but I have access to a Windows machine, so I can test it there if needed. Clib doesn't have any platform-related options, so I think it should also work there out of the box (I've used it as a standalone tool on Windows too).

Example of xmake.lua along with sample code which uses the installed package is in the first post 😉

I have a question - does the includedirs which come from the package should appear in gcc flags by default (I've checked with -D -v, they're not there unless I add them in xmake.lua)?
When I omit the add_includedirs("clib") in xmake.lua, compilation fails because it can't find the package's headers.

I've not used xmake before, so I possibly got something wrong in my understanding of it, sorry 😬

@waruqi

waruqi commented Apr 15, 2019

Copy link
Copy Markdown
Member

I have a question - does the includedirs which come from the package should appear in gcc flags by default (I've checked with -D -v, they're not there unless I add them in xmake.lua)?
When I omit the add_includedirs("clib") in xmake.lua, compilation fails because it can't find the package's headers.

You need add correct package name to find the given package.

add_requires("clib::clibs/bytes@0.0.4", {alias = "bytes"})

-- add modes: debug and release 
add_rules("mode.debug", "mode.release")

-- add target
target("xmake-test")

    -- set kind
    set_kind("binary")

    -- add files
    add_files("clib/bytes/*.c")
    add_files("src/*.c") 
    add_packages("bytes")  -- will call find_package to get includedirs and add -Ixxx
``

@RaZeR-RBI

Copy link
Copy Markdown
Contributor Author

I have a question - does the includedirs which come from the package should appear in gcc flags by default (I've checked with -D -v, they're not there unless I add them in xmake.lua)?
When I omit the add_includedirs("clib") in xmake.lua, compilation fails because it can't find the package's headers.

You need add correct package name to find the given package.

add_requires("clib::clibs/bytes@0.0.4", {alias = "bytes"})

-- add modes: debug and release 
add_rules("mode.debug", "mode.release")

-- add target
target("xmake-test")

    -- set kind
    set_kind("binary")

    -- add files
    add_files("clib/bytes/*.c")
    add_files("src/*.c") 
    add_packages("bytes")  -- will call find_package to get includedirs and add -Ixxx
``

Just tested it on Windows (using your example with alias), everything works fine. Shall we merge now?

@waruqi
waruqi merged commit d7d6f53 into xmake-io:dev Apr 15, 2019
@waruqi

waruqi commented Apr 15, 2019

Copy link
Copy Markdown
Member

Ok, Thanks!

@waruqi waruqi added this to the v2.2.6 milestone Apr 15, 2019
@waruqi

waruqi commented Apr 15, 2019

Copy link
Copy Markdown
Member

Just tested it on Windows (using your example with alias), everything works fine.

It works fine on macOS. 👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants