Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve rule API and build dependency order #6202

Open
8 tasks
waruqi opened this issue Mar 9, 2025 · 4 comments
Open
8 tasks

Improve rule API and build dependency order #6202

waruqi opened this issue Mar 9, 2025 · 4 comments

Comments

@waruqi
Copy link
Member

waruqi commented Mar 9, 2025

Roadmap

  • Insert custom rule before built-in rule
  • Source file granularity dependency order control
  • Unified DAG Implementation
  • Insert and remove build tasks in real time
  • Add a preparation phase before building to handle C++ module dependency scanning and other build preparation work
  • Support for build.fence
  • Support for job group for same rule
  • ...

Related

@waruqi waruqi added this to the v2.9.9 milestone Mar 9, 2025
@waruqi
Copy link
Member Author

waruqi commented Mar 10, 2025

Unified DAG Implementation

If no additional dependency chains are added, xmake will add a default dependency order according to its internal build rules.

rule("foo")
    on_build_file(function (target, jobgraph, sourcefile, opt)
        jobgraph:add_job(target:name() .. "/" .. sourcefile, function(job, opt)
            -- TODO
        end)
    end, {jobgraph = true})

Source file granularity dependency order control

rule("foo")
    on_build_files(function (target, jobgraph, sourcebatch, opt)
        for _, sourcefile in sourcebatch.sourcefiles do
            local job_name = target:name() .. "/" .. sourcefile
            jobgraph:add_job(job_name, function(job, opt)
                -- TODO
            end)

            -- add dependency chain, job -> other target jobs
            jobgraph:add_deps(job_name, other_target:name() .. "/buildfiles")
        end
    end, {jobgraph = true})

Insert and remove build tasks in real time

rule("foo")
    on_build_file(function (target, jobgraph, sourcefile, opt)
        local job_name = target:name() .. "/" .. sourcefile
        jobgraph:add_job(job_name, function(job, opt)
            -- TODO

            jobgraph:add_job("zoo/build", function (job, opt)
            end)

            jobgraph:remove_job("bar/buildfiles")
        end)
    end, {jobgraph = true})

Add a preparation phase before building

on_prepare scripts are called before all build scripts, we can do some things, e.g. scan c++ module source files, autogen ...

rule("scan_module_files")
    on_prepare(function (target, opt)
        -- scan module files
    end)

or

rule("scan_module_files")
    on_prepare(function (target, jobgraph, opt)
        jobgraph:add_job(target:name() .. "/scanfiles", function (job, opt)
            -- scan module files
        end)
    end, {jobgraph = true})

or

rule("scan_module_files")
    set_extensions("*.mpp")
    on_prepare_files(function (target, jobgraph, sourcebatch, opt)
        jobgraph:add_job(target:name() .. "/scanfiles", function (job, opt)
            -- scan module files
        end)
    end, {jobgraph = true})

Insert custom rule before built-in rule

We can use add_parents to insert deps to the custom rules in the given builtin rules.

-- the builtin rule
rule("c++")
    -- ...

-- c++ depend on foo
rule("foo")
    add_parents("c++")
    -- ...

Support for job group for same rule

rule("foo")
    on_build_files(function (target, jobgraph, sourcebatch, opt)
        local group_name = target:name() .. "/buildfiles"
        jobgraph:add_group(group_name, function ()
            for _, sourcefile in sourcebatch.sourcefiles do
                local job_name = target:name() .. "/" .. sourcefile
                jobgraph:add_job(job_name, function(job, opt)
                    -- TODO
                end)
            end
        end)

        -- add dependency chain, other target jobs -> this build group
        jobgraph:add_deps(other_target:name() .. "/buildfiles", group_name)
    end, {jobgraph = true})

@waruqi
Copy link
Member Author

waruqi commented Mar 10, 2025

This is an initial draft, any idea? @Arthapz @SirLynix @star-hengxing

@Arthapz
Copy link
Member

Arthapz commented Mar 10, 2025

It cover all my needs for module and the api is simple, I like it

@waruqi
Copy link
Member Author

waruqi commented Mar 11, 2025

Ok, I will implement them in next version.

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

No branches or pull requests

2 participants