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

Tests don't compile with MSVC (Windows) #174

Closed
arcuru opened this issue Sep 20, 2017 · 6 comments
Closed

Tests don't compile with MSVC (Windows) #174

arcuru opened this issue Sep 20, 2017 · 6 comments

Comments

@arcuru
Copy link
Contributor

arcuru commented Sep 20, 2017

TLDR - There are issues with doing the exercises under Visual Studio (and likely other non-GCC/Clang compilers like ICC). This can be fixed by adding the following function defs to all of the test\test_*.c files.

void setUp(void) { }
void tearDown(void) { }

This is because Unity uses a non-standard method to support optional setUp and tearDown methods. GCC and Clang methods are implemented in Unity (they support __attribute__((weak)) and/or #pragma weak I think). Other compilers may do the same, but MSVC doesn't support those as far as I can tell.

Someone could fix the issue for us by patching Unity with the correct method for MSVC (you can pass comments to the linker using a pragma), but that doesn't fix it for other compilers that don't support the weak linking either.

It does work fine using the various unix implementations on Windows (WSL and MSYS) since they just use GCC.

@wolf99
Copy link
Contributor

wolf99 commented Sep 20, 2017

Are the folks on the Unity project aware of this issue? Is there a related issue on their repo?

@arcuru
Copy link
Contributor Author

arcuru commented Sep 20, 2017

I should clarify, according to their docs those functions are required unless "you're using a compiler that is configured to make these functions optional".

So really it's an issue on us for only supporting gcc/clang.

@ryanplusplus
Copy link
Member

@patricksjackson I'm not really familiar with building C on Windows without Cygwin (ugh) or MinGW (slightly less ugh). I thought that MSVC wasn't even C99 compliant.

So, is there a way for someone to easily set up MSVC to build our C99 code? Where would you get make if you just installed the Microsoft tools?

Basically, is this something worth supporting, or is it so painful that the crappy GNU options are actually better?

@wolf99
Copy link
Contributor

wolf99 commented Sep 22, 2017

FYI, MSVC doesn't really support C99. It supports it insofar as updates to the C++ compiler also apply to some C code. MS picked C++ over C as their language of choice for native code. There is a discussion on it here https://social.msdn.microsoft.com/Forums/SECURITY/en-US/fa17bcdd-7165-4645-a676-ef3797b95918/details-on-c99-support-in-msvc?forum=vcgeneral

Although, this stance seems to vary depending on which way the wind is blowing and MSVC version: https://stackoverflow.com/questions/9610747/which-c99-features-are-available-in-the-ms-visual-studio-compiler

The most specific official details I've found on support are here https://msdn.microsoft.com/en-us/library/hh567368.aspx?f=255&MSPPError=-2147217396.

For my 2c: I've struggled getting MinGW/MYSYS setup before but did get it working to differing degrees on various occasions. GCC on WSL though is a much (much) easier-to-use alternative to recommend.

For these reasons I would recommend being wary of adding specific support for MSVC building. For the specific case in this issue, the setUp() and tearDown() additions, it seems a reasonable change (as it may also apply to other compilers outside of MSVC), but maybe MSVC-specific changes should be considered on a case-by-case basis going forward, based on the amount of work involved.

@ryanplusplus
Copy link
Member

@wolf99 Thanks for all the background.

I agree with you: the specific case of setUp() and tearDown() are so minor that it's not a real issue adding them in.

@arcuru
Copy link
Contributor Author

arcuru commented Sep 23, 2017

FWIW, Visual Studio works to build the exercises pretty easily. I haven't tried to use the Makefiles (you're supposed to be able to import them I think) but you can just make an empty project pointed to the exercise directory and it sets everything up for you. It's a useful alternative if the people doing the exercises are in Windows and have never used the command line, or would just rather have the VS capabilities.

@wolf99 WSL is also my recommendation for getting the Unix tools on Windows :) The only issue I've had recently is with tools that don't handle CRLF line endings.

I'd also agree that making non-standard changes to support a particular compiler vendor isn't the best plan, but this change is the exact opposite. The only reason it currently works is because Unity wrote non-standard workarounds for GCC/Clang.

Also, it's really not worthwhile to try to get Unity to support Weak Symbols for every compiler (or even just adding MSVC), I mentioned it but it's not worth it when setup and teardown work fine.

0xbarrett added a commit to 0xbarrett/xc that referenced this issue Oct 31, 2017
wolf99 pushed a commit that referenced this issue Nov 9, 2017
* Start sublist

* Finish tests and example

* Run indent script

* Add additional test for signed integer

* Add exercise to config.json

* Update README

* Update per review comments

* Ignore all tests except for the first one

* Refactor naming

* Formatter

* Add setUp and tearDown per #174; add comment to first TEST_IGNORE()

* Switch sublist to non-core
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

No branches or pull requests

3 participants