xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.87k stars 776 forks source link

Pass file's path when trying to export all symbols #5601

Closed 01Pollux closed 2 weeks ago

01Pollux commented 2 weeks ago

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

Currently, there is no way to know the file path from which a symbol was exported.

Describe the solution you'd like

It would be useful to have a way to export all symbols from files inside the 'Public/' directory, for example. The pseudocode could look like this:

target("bar")
    set_kind("shared")
    add_files("src/bar.cpp")
    add_rules("utils.symbols.export_all", {export_filter = function (symbol, path)
        if path:find("Public/", 1, true) then
            return true
        end
    end})

Describe alternatives you've considered

No response

Additional context

No response

waruqi commented 2 weeks ago

If we pass sourcefile as path, the implementation is very complicated and it is not very accurate. This is because some rules automatically generate objectfiles and do not save the corresponding sourcefiles.

So I think it might be better and more accurate to pass objectfile as the path.

waruqi commented 2 weeks ago

try this patch. https://github.com/xmake-io/xmake/pull/5608

target("bar")
    set_kind("shared")
    add_files("src/bar.cpp")
    add_rules("utils.symbols.export_all", {export_filter = function (symbol, opt)
        local filepath = opt.sourcefile or opt.objectfile
        if filepath and filepath:find("bar.cpp", 1, true) and symbol:find("add", 1, true) then
            print("export: %s at %s", symbol, filepath)
            return true
        end
    end})