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

Better control over the order of execution of rules #2866

Closed
waruqi opened this issue Sep 26, 2022 · 2 comments
Closed

Better control over the order of execution of rules #2866

waruqi opened this issue Sep 26, 2022 · 2 comments

Comments

@waruqi
Copy link
Member

waruqi commented Sep 26, 2022

Is your feature request related to a problem? Please describe.

Although add_deps("xxx", {order = true}) can also control the order of rules, we can't get it to be executed before some of the built-in rules if it's a user-defined rule.

#2817
#2814

for example: custom cppfront rule will generate .cpp from .cpp2 and it need be call before c++/c++.modules rules.

Describe the solution you'd like

I haven't figured out how to do it yet.

Describe alternatives you've considered

No response

Additional context

No response

@waruqi
Copy link
Member Author

waruqi commented Sep 26, 2022

I think it would probably be nice to offer the possibility of rewriting the built-in rules, and we could do other things like adding c++ file extensions and so on, and be able to control the order of dependencies using a consistent approach.

like this.

rule("cppfront")
    set_extensions(".cpp2")
    on_load(function (target)
        -- modify and replace the builtin rule
        local rule = target:rule("c++.build"):clone()
        rule:add("deps", "cppfront", {order = true})
        target:rule_add(rule)
    end)
    on_build_file(function (target, sourcefile, opt)
        print("build cppfront file")
    end)

target("test")
    set_kind("binary")
    add_rules("cppfront")
    add_files("src/*.cpp")
    add_files("src/*.cpp2")

@Arthapz
Copy link
Member

Arthapz commented Sep 27, 2022

I like the clone method, it will provide a better way to handle generated C++ as we don't need anymore to build the files by hand (and it enable c++ module generation)

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