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

Re-exporting a module in a modulemap does not work #80216

Open
Steelskin opened this issue Mar 21, 2025 · 1 comment
Open

Re-exporting a module in a modulemap does not work #80216

Steelskin opened this issue Mar 21, 2025 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@Steelskin
Copy link
Contributor

Description

Consider the following modulemap file:

module Interop {
    header "interop.h"
    requires cplusplus
}

module Container {
    export Interop
}

The modulemap documentation states that:

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

However, when importing Container in Swift, the symbols defined in interop.h are not available.

Reproduction

// ImportInterop.swift
import Container

var result = InteropClass();
result.property = true;
// interop/interop.h
#pragma once

class InteropClass {
public:
    bool property = false;
};
// interop/module.modulemap
module Interop {
    header "interop.h"
    requires cplusplus
}

module Container {
    export Interop
}

Build command:

swiftc -v -module-cache-path clang-module-cache/ -Xfrontend -cxx-interoperability-mode=default -I interop/ -c ImportInterop.swift -o ImportInterop.o

Expected behavior

The above code should compile properly. InteropClass should be a valid symbol.

Environment

Swift 6.1-dev (recent-ish trunk build)

Additional information

No response

@Steelskin Steelskin added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 21, 2025
@Steelskin
Copy link
Contributor Author

This comment on the LLVM bug leads me to believe we have been holding the modulemap for ucrt wrong:

Clang header modules can only export entities that they have a declaration for. export in a module map just allows declarations to be exported, it doesn't add any imports itself. The Container module needs a header that includes interop.h.

export does not actually import the declarations, which is what we thought was happening. I am not certain what the best way to solve the issue would be. Maybe the swift compiler should be making sure all of the symbols are re-exported since this is how we are using module maps for C++/Swift interop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants
@Steelskin and others