Skip to content

Introduce SWIFT_EXTERN_RUNTIME_EXPORT for Windows #6820

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

Merged
merged 4 commits into from
Jan 25, 2017
Merged

Introduce SWIFT_EXTERN_RUNTIME_EXPORT for Windows #6820

merged 4 commits into from
Jan 25, 2017

Conversation

hughbe
Copy link
Contributor

@hughbe hughbe commented Jan 14, 2017

IRGen includes Metdata.h. This means that Metadata.h has to be able to be compiled with MSVC, even though its part of the runtime.

The correct syntax for dll exporting an extern C symbol is

extern "C" __declspec(dllexport_) ...

However, current we do

__declspec(dllexport) ... extern "C"

This means that we get several hundred MSVC errors compiling IRGen.

The fix is to introduce a macro, SWIFT_EXTERN_RUNTIME_EXPORT that fixes the declspec errors.

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov slavapestov self-assigned this Jan 15, 2017
@@ -216,6 +216,7 @@
// But some of the runtime entries are invoked directly from
// the foundation. Therefore they should be visible.
#define SWIFT_RT_ENTRY_VISIBILITY SWIFT_RUNTIME_EXPORT
#define SWIFT_EXTERN_RT_ENTRY_VISIBILITY SWIFT_EXTERN_RUNTIME_EXPORT
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be SWIFT_RT_EXTERN_ENTRY_VISIBILITY at the very least.

Is there ever a case we wouldnt want the extern "C" on the interface?

Copy link
Contributor Author

@hughbe hughbe Jan 16, 2017

Choose a reason for hiding this comment

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

Casting.cpp

As well as in Enum.cpp

Heap.cpp

As well as HeapObject.cpp

As well as Metadata.cpp

As well as SwiftObject.mm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Judging by the number of these, I say we keep these two separate? I'll rename to SWIFT_RT...

Copy link
Contributor

Choose a reason for hiding this comment

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

Every export from the Swift runtime ought to be extern "C".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, interesting only cpp files have export without extern - maybe this is an oversight.

Do we make the cpp files use extern C, or simply remove them - not sure if the headers are already annotated as extern C

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a better way to make intentions explicit there would be to have a SWIFT_CALLED_VIA_SILGEN_NAME marker. That would incorporate extern "C" and potentially be useful for keeping the C++ side and the Swift side in sync.

Copy link
Contributor

Choose a reason for hiding this comment

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

…but IMO that ought to be a job for a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I like that. I'll submit a PR once I get the other extern c stuff merged :)

Cheers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

…but IMO that ought to be a job for a follow-up PR.

Took the words out of my mouth ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Great minds think alike, obviously.

#else
#define SWIFT_EXTERN_RUNTIME_EXPORT SWIFT_RUNTIME_EXPORT extern "C"
#endif

Copy link
Member

Choose a reason for hiding this comment

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

This should be unnecessary. Use the form from _MSC_VER clause always.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, fixed

@hughbe hughbe dismissed compnerd’s stale review January 20, 2017 14:56

Completely updated :D

@hughbe
Copy link
Contributor Author

hughbe commented Jan 20, 2017

Okay, I've updated this PR to do the following:

  • Define SWIFT_RUNTIME_EXPORT in terms of extern "C"
  • Remove all references to extern "C" if we have SWIFT_RUNTIME_EXPORT/SWIFT_RUNTIME_STDLIB_INTERFACE/SWIFT_RT_ENTRY_VISIBILITY

I've tested on Windows, everything works, but I'll trigger on Linux/OSX (for objc only methods) before the review

I'm attaching a summary of my work as well - it details examples where we used one of these macros without extern "C". Most of these will be cleaned up in a future PR

SWIFT_RT_ENTRY_VISIBILITY.txt
SWIFT_RUNTIME_EXPORT.txt
SWIFT_RUNTIME_STDLIB_INTERFACE.txt

@hughbe
Copy link
Contributor Author

hughbe commented Jan 20, 2017

@swift-ci please smoke test

1 similar comment
@hughbe
Copy link
Contributor Author

hughbe commented Jan 20, 2017

@swift-ci please smoke test

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor

@hughbe Sorry, for now only those with commit access can trigger CI.

@hughbe
Copy link
Contributor Author

hughbe commented Jan 21, 2017

I do have commit access!

@slavapestov
Copy link
Contributor

Oh, well then CI was just being flaky.

@hughbe
Copy link
Contributor Author

hughbe commented Jan 22, 2017

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 16cbfa45a1fdddb657b4c431313ebb79c638fcca
Test requested by - @hughbe

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 16cbfa45a1fdddb657b4c431313ebb79c638fcca
Test requested by - @hughbe

@slavapestov
Copy link
Contributor

@compnerd Mind clicking the big green button? :)

@compnerd
Copy link
Member

Yeah, given the follow up work and the changes now, LG.

@compnerd compnerd merged commit ac57b66 into swiftlang:master Jan 25, 2017
@gparker42
Copy link
Contributor

Thanks, Hugh.

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.

5 participants