Skip to content

make build with MSVC #21578

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

Closed
wants to merge 1 commit into from
Closed

make build with MSVC #21578

wants to merge 1 commit into from

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Jan 1, 2019

This adjusts the sources to build with Visual Studio. This is helpful
in cases where the compiler needs to be debugged on Windows.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

This adjusts the sources to build with Visual Studio.  This is helpful
in cases where the compiler needs to be debugged on Windows.
@compnerd
Copy link
Member Author

compnerd commented Jan 1, 2019

@jrose-apple - the constexpr doesn't imply const. Using the appropriately matching type seems to be needed, I can't find anything else that makes both clang and cl happy.

@mikeash - I'm not sure if there is any option for the __swift_ssize_t type definition. cl doesn't support C11 :-(. Perhaps I should check the C version instead?

I'd like to figure out what we can do here so I can setup continuous builds for the compiler using cl.

@compnerd
Copy link
Member Author

compnerd commented Jan 1, 2019

@swift-ci please test

@@ -29,11 +29,19 @@ typedef __SIZE_TYPE__ __swift_size_t;
#endif

// This selects the signed equivalent of the unsigned type chosen for size_t.
#if defined(_MSC_VER)
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I suppose that this should be:

#if defined(_MSC_VER) && !defined(__clang__) ...

@jrose-apple
Copy link
Contributor

@jrose-apple - the constexpr doesn't imply const. Using the appropriately matching type seems to be needed, I can't find anything else that makes both clang and cl happy.

I think we want both here, really: const for unchanging and constexpr for "must compile down to a single constant".

#if defined(_MSC_VER)
#if defined(_M_X86) || defined(_M_ARM)
typedef int ssize_t;
#elif defined(_M_AMD64) || defined(_M_ARM64)
Copy link
Contributor

Choose a reason for hiding this comment

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

_WIN64 then _WIN32, maybe? Although I'm wondering why MSVC is ever even looking at this header; it should always be compiled with the just-built Clang, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

Whoah... its a wild @jrose-apple!

Copy link
Member Author

Choose a reason for hiding this comment

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

@jrose-apple - nope, because this is getting indirectly included into the compiler. It is really sad that we cannot limit this header to just the stdlib/runtime which I would really prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems…wrong. Maybe that's the thing worth tackling: figuring out which runtime / shims headers need to go into the compiler and separating them out.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jrose-apple I agree. I had tried to remove the use of the header, but @jckarter didn't want to lose the re-use of the types defined in the headers IIRC.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's what I would recommend; the only place we need to avoid using the platform headers is when importing the header to build the standard library.

Copy link
Member Author

Choose a reason for hiding this comment

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

ssize_t is not available on all platforms as it is not mandated by the standard, it is an extension.

Copy link
Contributor

@jrose-apple jrose-apple Jan 7, 2019

Choose a reason for hiding this comment

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

It's probably the same as ptrdiff_t, if SSIZE_MAX isn't defined? Or intptr_t.

EDIT: Or std::make_signed<std::size_t>::type.

Copy link
Member Author

Choose a reason for hiding this comment

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

SSIZE_MAX is also not available IIRC. Yes, we should be able to use std::make_signed<std::size-t>::type but obviously only in the C++ context.

Copy link
Contributor

@jrose-apple jrose-apple Jan 8, 2019

Choose a reason for hiding this comment

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

Yeah, I meant to use the absence of SSIZE_MAX as a signifier to use a fallback type, but in practice I think it'd be valid to say that these headers must be included in either a Swift or a C++ context. (Note that Swift should be tested first, since someday we'll probably have C++-in-Swift. Somehow.)

@compnerd
Copy link
Member Author

compnerd commented Jan 7, 2019

I think we want both here, really: const for unchanging and constexpr for "must compile down to a single constant".

Unfortunately, MSVC doesn't like the const constexpr :-(. I can try again with the new 2019 preview though.

@jrose-apple
Copy link
Contributor

I think we want both here, really: const for unchanging and constexpr for "must compile down to a single constant".

Unfortunately, MSVC doesn't like the const constexpr :-(. I can try again with the new 2019 preview though.

Or conditionalize it somehow. Or use an enum instead of a constant, though I hate doing that.

@mikeash
Copy link
Contributor

mikeash commented Jan 14, 2019

Catching up after an extended winter break.... @compnerd The generic __swift_ssize_t thing is nice to have, but it seems fine to have a couple of simple special-cased typedefs for a platform that doesn't support it.

@compnerd
Copy link
Member Author

#21979 takes care of the storage

@compnerd compnerd closed this Jan 18, 2019
@compnerd compnerd deleted the cl-support branch January 18, 2019 19:45
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