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

Add support for libstdc++ standard library modules #5869

Merged
merged 3 commits into from
Nov 26, 2024

Conversation

Juvwxyz
Copy link
Contributor

@Juvwxyz Juvwxyz commented Nov 22, 2024

An installed source form of module std and std.compat has been merged into gcc trunk branch. It's time to add support for them.
[Bug 106852](c++lib-std-module) - Implement C++23 P2465R3 Standard Library Modules std and std.compat

GCC provides a libstdc++.modules.json file alongside libstdc++.so, which tells the build system where the files are. We can also find this file with :

gcc -print-file-name=libstdc++.modules.json

Content in the json may looks like this:

{
  "version": 1,
  "revision": 1,
  "modules": [
    {
      "logical-name": "std",
      "source-path": "../include/c++/15/bits/std.cc",
      "is-std-library": true
    },
    {
      "logical-name": "std.compat",
      "source-path": "../include/c++/15/bits/std.compat.cc",
      "is-std-library": true
    }
  ]
}

The structure of this json file is basicly the same as the one provided by llvm.

Known issue

Currently, these two files cannot compile with -D_GLIBCXX_USE_CXX11_ABI=0 option, so I set ths macro to 1 if a target is compile with std modules. This issue may related to #2716 and #3855 .

@waruqi waruqi requested a review from Arthapz November 22, 2024 10:11
return nil
end

local modules_json = json.decode(io.readfile(modules_json_path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use json.loadfile

return os.iorunv(compinst:program(), {"-print-file-name=libstdc++.modules.json"}, {envs = compinst:runenvs()})
end
}
modules_json_path = modules_json_path:trim()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modules_json_path maybe nil,

if modules_json_path then
    modules_json_path = modules_json_path:trim()
    if os.isfile(modules_json_path) then
        return modules_json_path
    end
end

if not path.is_absolute(module_file_path) then
module_file_path = path.join(modules_json_dir, module_file_path)
end
table.join2(std_module_files, {module_file_path})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            table.insert(std_module_files, module_file_path)

@waruqi waruqi added this to the v2.9.7 milestone Nov 26, 2024
@waruqi waruqi merged commit 4c75133 into xmake-io:dev Nov 26, 2024
@Juvwxyz Juvwxyz deleted the gcc/stdmodules branch November 26, 2024 05:13
@waruqi
Copy link
Member

waruqi commented Nov 26, 2024

@waruqi
Copy link
Member

waruqi commented Nov 26, 2024

#5887

@waruqi waruqi mentioned this pull request Nov 26, 2024
if target:policy("build.c++.gcc.modules.cxx11abi") then

-- libstdc++ std modules cannot compile with -D_GLIBCXX_USE_CXX11_ABI=0
if target:policy("build.c++.modules.std") or target:policy("build.c++.gcc.modules.cxx11abi") then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants