Skip to content

Re-exporting a module in a modulemap does not seem to work #132792

Open
@Steelskin

Description

@Steelskin

Summary

Consider the following modulemap file:

module Interop {
    header "interop.h"
    export *
}

module Container {
    export Interop
}

I would expect that using the Container module would contain all of the definitions from the Interop module, as the documentation seems to indicate:

An export-declaration specifies which imported modules will automatically be re-exported as part of a given module’s API.

However, I have found that this does not work as expected.

Repro steps

// module.modulemap
module Interop {
    header "interop.h"
    export *
}

module Container {
    export Interop
}
// interop.h
# pragma once

int g_property = 0;

Build commands:

clang -cc1 -emit-module -o Container.pcm -fmodules module.modulemap -fmodule-name=Container
clang -cc1 -emit-module -o Interop.pcm -fmodules module.modulemap -fmodule-name=Interop

I could not figure an easy way to get the symbols out of the PCM, but I can infer the lack of g_property symbol in the Container module in 2 ways:

  1. strings does not find g_property in Interop.pcm
$ strings Container.pcm | grep g_property
$ string Interop.pcm | grep g_property

g_property
  1. clang -module-file-info does not list interop.h for Container.pcm
$ clang -module-file-info Container.pcm
[...]
    Use libc++ (rather than libstdc++) [-stdlib=]: No
  Preprocessor options:
    Uses compiler/target-specific predefines [-undef]: Yes
    Uses detailed preprocessing record (for indexing): No
    Predefined macros:
  Input file: [..]/module.modulemap
  Diagnostic options:
[...]
$ clang -module-file-info Interop.pcm
[...]
    Use libc++ (rather than libstdc++) [-stdlib=]: No
  Preprocessor options:
    Uses compiler/target-specific predefines [-undef]: Yes
    Uses detailed preprocessing record (for indexing): No
    Predefined macros:
  Input file: [..]/module.modulemap
  Input file: [..]/interop.h
  Diagnostic options:
[...]

Related issue

This is problematic when using modulemaps with Swift, see swiftlang/swift#80216

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header Modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions