Skip to content

Cleaning up the build system - #169

Closed
jd-gascuel wants to merge 4 commits into
ccache:masterfrom
jd-gascuel:pr1-build
Closed

jd-gascuel wants to merge 4 commits into
ccache:masterfrom
jd-gascuel:pr1-build

Conversation

@jd-gascuel

Copy link
Copy Markdown

Hi Joel, Hi Anders,

I spend the day squashing and re-basing my fork (sorry, dropping the previous PR also drop all the discussions we had there... Sorry for that!).

Here is a first cleaned PR that I can propose you. The idea is just to have a common ground when building various branches/forks/mirror/whatsoever versions of ccache...
But this PR does not change anything at the behavior of the actual code.

Summary:

  • Upgrade config.guess and config.sub to 2017-03 version: this is needed to detect MSYS2 platform.
  • Upgrade configure.ac (and *.in) to pass clean variables about the detected platform/compiler
  • Check HAVE_XXX_H before including various files detected by configure.
  • Move compiler_is_XXX() predicates at the beginning of ccache.c
  • Make input_file, output_object and make_relative_path() so we can unit test them.

--> Please let me know if you are happy with that.

All the best,

@afbjorklund

Copy link
Copy Markdown
Contributor

Why did you have to rename util.c ? Did the name conflict with something on Windows ?

Otherwise the upgrade of autotools and OBJEXT/LIBEXT looked reasonable, but not
so sure about the compiler - and I know that @jrosdahl had some concerns about that.

Basically this will be impossible to test, with everything ifdefd in the Makefile like that...

@afbjorklund

Copy link
Copy Markdown
Contributor

But I can give it a try with mingw-w64, maybe some of it is enough to get #122 going again.

@jd-gascuel

jd-gascuel commented Mar 28, 2017 •

Copy link
Copy Markdown
Author

Hello Anders,

  1. There is two: util.c and test/util.c ... perfectly legal on linux, but just crashes the brain of the windows linker. But my choice of name is probably just wrong. One can also consider just merging them both.

  2. The compiler detection is just to be used at compiling ccache. It is NOT aimed at changing its behavior. in any way.
    Ideally a binary of ccache compiled with cl using MSYS2 should be able to work for cl, gcc, cc, llvm, etc.
    I will provide an AppVeyor matrix that test just that...

  3. About Windows compatibility, I am pretty sure it will not suffice...
    I have another PR to propose, that should improve greatly the mingw support:

    • Adding a pair of path_eq() and path_startswith() replacements of the equivalent str_*() functions. The idea being that for linux they to the same, but for windows, path are case-insensitive, you use both / or \.
    • changing make_relative_path() to use the above, and take cares of the driver and server syntax.
    • plus lots of small changes that are direct consequence of this.

@afbjorklund

Copy link
Copy Markdown
Contributor

@jd-gascuel : seems you have a typo in "psapi" (spelled as "Psapi"), which fails the build...
(I suppose it doesn't matter either way on a DOS file system, but better keep it as lowercase)

/usr/bin/i686-w64-mingw32-ld: cannot find -lPsapi
/usr/i686-w64-mingw32/lib/libpsapi.a

Comment thread configure.ac
case $host in
*mingw32* | *mingw64* | *cygwin* | *wince* | *mingwce*)
windows_os=yes
ccache_os=mingw

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the difference between MinGW and Windows ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The good question is: what is the difference between MinGW and MSYS2 ?
I found at least one:

  • MSYS2: You should link with Psapi.lib
  • MINGW: You should link with -lpsapi (sorry for the mixed case typo)

Comment thread configure.ac

*msys*)
ccache_os=msys
AC_DEFINE(CCACHE_MSYS, 1, Compiling on a MSYS2 platform)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the difference between MSYS and Windows ?

Comment thread configure.ac

*apple*)
ccache_os=mac
AC_DEFINE(CCACHE_MAC, 1, Compiling on an Apple platform)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This platform is normally called Darwin, after the uname

@afbjorklund

afbjorklund commented Mar 28, 2017 •

Copy link
Copy Markdown
Contributor

Ah, I see. Maybe test/util.c should be called test/test_util.c or something.

@jd-gascuel

jd-gascuel commented Mar 28, 2017 •

Copy link
Copy Markdown
Author

... or something. Because there is already a test/test_util.c too...

@afbjorklund

Copy link
Copy Markdown
Contributor

Test results on MinGW-w64/Wine (i686) doesn't look all bad, actually!
Mostly it's the -fdiagnostics-color that is causing some failures, plus:

test/test_conf.c:345: Failed assertion:
  Suite:      conf
  Test:       conf_set_new_value
  Assertion:  conf_set_value_in_file("ccache.conf", "stats", "chocolate", &errmsg)

test/test_conf.c:357: Failed assertion:
  Suite:      conf
  Test:       conf_set_existing_value
  Assertion:  conf_set_value_in_file("ccache.conf", "path", "vanilla", &errmsg)

@jd-gascuel

Copy link
Copy Markdown
Author

I have that in my branch: It just drops color under mingw or msys:

static bool
color_output_possible(void)
{
#ifdef _WIN32
	return false;
#else
	const char *term_env = getenv("TERM");
	return isatty(STDERR_FILENO) && term_env && strcasecmp(term_env, "DUMB") != 0;
#endif
}

@afbjorklund

Copy link
Copy Markdown
Contributor

Well, the problem was the /* #undef HAVE_UNSETENV */ in config.h
This causes x_unsetenv to set it to "" instead, and a check was missing:

--- a/ccache.c
+++ b/ccache.c
@@ -1710,7 +1710,7 @@ calculate_common_hash(struct args *args, struct mdfour *hash)
        // Possibly hash GCC_COLORS (for color diagnostics).
        if (compiler_is_gcc(args)) {
                const char *gcc_colors = getenv("GCC_COLORS");
-               if (gcc_colors) {
+               if (gcc_colors && gcc_colors[0] != '\0') {
                        hash_delimiter(hash, "gcccolors");
                        hash_string(hash, gcc_colors);
                }

@jd-gascuel

jd-gascuel commented Mar 28, 2017 •

Copy link
Copy Markdown
Author

...
And I have also that in my branch, found from some PR around. It does helps too:

// This is like unsetenv.
void x_unsetenv(const char *name)
{
#ifdef HAVE_UNSETENV
	unsetenv(name);
#elif defined(_WIN32)
	char *str = format("%s=", name);
	putenv(str);
	free(str);
#else
	putenv(x_strdup(name)); // Leak to environment.
#endif
}

@afbjorklund

Copy link
Copy Markdown
Contributor

Yeah, it seemed to choke on the suffix not fitting into the DOS conventions;

test/test_conf.c:345: Failed assertion:
  Suite:      conf
  Test:       conf_set_new_value
  Expression: conf_set_value_in_file("ccache.conf", "stats", "chocolate", &errmsg)
  Message:    rename ccache.conf.tmp.anders-ThinkPad.8.P1kAlM to ccache.conf: No such file or directory

test/test_conf.c:357: Failed assertion:
  Suite:      conf
  Test:       conf_set_existing_value
  Expression: conf_set_value_in_file("ccache.conf", "path", "vanilla", &errmsg)
  Message:    rename ccache.conf.tmp.anders-ThinkPad.8.iG2Kb7 to ccache.conf: No such file or directory

Probably create_tmp_fd needs to be taught about using 8+3 somehow.

@jd-gascuel

Copy link
Copy Markdown
Author

What is your settings for MinGW-w64/Wine (i686) ?
Can I re-enable them in my branch, just to be sure to produce compatible stuff... ?

@afbjorklund

Copy link
Copy Markdown
Contributor

Basically: ./configure --host=i686-w64-mingw32 && make quicktest
Thought about adding a Dockerfile for it ? (gcc-mingw-w64-i686 + wine)

@afbjorklund

Copy link
Copy Markdown
Contributor

And apparently MinGW has some own "mkstemp", that configure finds - but doesn't work.
Binary file /usr/i686-w64-mingw32/lib/libmingwex.a matches

That was the last two fails (switching to the "cheap and nasty" replacement works better).

@afbjorklund

Copy link
Copy Markdown
Contributor

@jd-gascuel : Were you able to use the Dockerfile ?

make docker

Should be easy to extend to "clang" and "mingw", too...
Probably move them into subdirectories or something ?

@afbjorklund

Copy link
Copy Markdown
Contributor

Uploaded the passing code as 00633e3...36c54c7, if it helps you somehow ?
We'll need to upgrade the Travis build to 16.04 LTS (trusty), for this to work...

        - os: linux
          compiler: i686-w64-mingw32-gcc
          sudo: required
          dist: trusty
          env: HOST="--host=i686-w64-mingw32" TEST="test/main.exe"

@jd-gascuel

jd-gascuel commented Mar 28, 2017 •

Copy link
Copy Markdown
Author

Oups... I am lost here: how do I fetch and merge your uploaded patch into my PR ?
(git newbie question, sorry).

...

Ok I made a wget URL.patch + git apply: it squashed everything in one step.

@jd-gascuel

jd-gascuel commented Mar 28, 2017 •

Copy link
Copy Markdown
Author

Oups. I got

The program 'i686-w64-mingw32-gcc' is currently not installed...

Reverting.

@afbjorklund

Copy link
Copy Markdown
Contributor

I suppose mentioning the branch name (afbjorklund/mingw-build) would have helped too...

@afbjorklund

Copy link
Copy Markdown
Contributor

And yeah, adding the requirements would be needed too.

@afbjorklund

Copy link
Copy Markdown
Contributor

That "mkstemp" stuff was from 18c7730, by the way.

@afbjorklund

afbjorklund commented Mar 29, 2017 •

Copy link
Copy Markdown
Contributor

Apparently one can use wine1.6-amd64 for running 64-bit binaries,
so there is no particular to not use --host=x86_64-w64-mingw32 ?

test/main.exe: PE32+ executable (console) x86-64, for MS Windows
PASSED: 480 assertions, 95 tests, 10 suites

@afbjorklund

afbjorklund commented Mar 29, 2017 •

Copy link
Copy Markdown
Contributor

Updated the branch for #119, would be nice to combine forces for Appveyor with #69 ?

https://github.com/TheOneRing/ccache/blob/fa4945221ddc8f1b38df23fb113a193ef117dc4a/appveyor.yml

https://github.com/jd-gascuel/ccache/blob/e946e2b6e3987168c915933fb334cbcaf7661d3a/.appveyor.yml

I wonder where that "usleep" went, maybe I left it in Windows or something ? (nanosleep)


Will leave this PR as the request for supporting Visual Studio / Windows as a development platform ?

As @jrosdahl said (#162 (comment)), not so sure...

The other two relied heavily on just using MinGW, so wasn't too concerned with supporting Windows.

Seems to be working with Wine, haven't tried on Win.


I'm OK with supporting Mac using clang in the main code.

Also OK with supporting Win - by using MinGW and Wine.

But am not so sure about supporting Xcode / Visual Studio ?

That would require me actually running tests on the real thing.

@jd-gascuel

Copy link
Copy Markdown
Author

Hi @afbjorklund ,

This PR is not about supporting Windows. It is just about having a common ground to make it easier to share code with a branch/fork/XXX that do support windows.

This is why I did not include any change specific for MSYS2 or MinGW.

About your (not for the PR usleep() question), I can propose the simple answer I used in my branch:

  • usleep() is in micro seconds. But does nit exist in the Windows world.
  • nanosleep() is not so much an option, because it lacks portability.
  • On the other end, for decades Windows do have a Sleep()function, which is in milli-seconds.

The good point is tha ccache indeed use just milli-seconds resolution (ie. starting at 1ms, and doubling until done), so a quiet simple patch to bool lockfile_acquire()is just:

#ifdef _WIN32
        // We are lucky: Windows have ms resolution, which is enough here.
        Sleep(to_sleep/1000);
#else
        usleep(to_sleep);
#endif

Regards,

@jd-gascuel jd-gascuel changed the title Cleanup the build system Cleaning up the build system Mar 29, 2017
@afbjorklund

Copy link
Copy Markdown
Contributor

Thanks for clarifying, but still the changes proposed only affects Windows as a platform...
Maybe it would be interesting to look into testing it in the cloud, but it's not cross-platform.

Your change with Sleep looks good, will take the platform discussion to the mailing list.
I can probably find Mac OS X 10.9 or Windows 7, but latest/greatest isn't always available.

@jd-gascuel

jd-gascuel commented Mar 31, 2017 •

Copy link
Copy Markdown
Author

I am quiet new to ccache development, but I found AppVeyor really useful and efficient.

My current AppVeyor YML compiles on gcc 32 and 64 bits, Visual 2013 32 and 64 bits, and Visual 2015 32 and 64 bits. And for each of them, runs the full test suite with gcc, g++ and cc. Most probably overkill in the long run, but interesting and useful during the hard-coding time.
As it is integrated with github, one can also directly see status of each commit or PR, just like for Travis... which is certainly great to help code maintainability.

@afbjorklund

afbjorklund commented Apr 1, 2017 •

Copy link
Copy Markdown
Contributor

Yeah, it's definitely useful (with Travis or Appveyor). But some things needs direct access to the actual platform in order to do development, and when running locally it is easier to set up Docker or Vagrant ?

Anyway, the new MSYS2 system is kinda neat (I like pacman) and upgrading to 64-bit was needed anyway because of C99 and because of critical bugs (printf ? sheesh) in the old 32-bit MinGW/MSYS environment.

Apparently there's some things to be done with symlinks: MSYS2-dont-use-symlinks.patch

So in order to work on Windows, those should be addressed (with tests) and the rest fixed ?

@afbjorklund

afbjorklund commented Apr 1, 2017 •

Copy link
Copy Markdown
Contributor

Apparently MSYS2 does not compile for Windows (_WIN32) by default (have to use -mwin32 now),
which is why the test case fails... It also doesn't define __MINGW32__ (nor __MINGW64__) anymore.

Like you reported earlier, the uname is now a weird "MSYS_NT-6.4" instead of "MINGW32_NT-6.1"
I suppose that test.sh should accept either MINGW* or MSYS*, and in either case (upper/lower).


And we need a better way to detect compiler, than looking at the name of binary (as it fails)

So need to go beyond the first line of the version string, since that doesn't have any real info:

gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)

Probably look for the macros instead.

#define __GNUC__ 5
#define __clang__ 1

#define __llvm__ 1
#define __MINGW32__ 1
#define __MINGW64__ 1
#define __MSYS__ 1

@afbjorklund

afbjorklund commented Apr 1, 2017 •

Copy link
Copy Markdown
Contributor

@jd-gascuel : Oh, and I found the old nanosleep code (44fbd43)
It can use that where available, and milliseconds on Windows...

We only sleep for 1 millisecond (and longer) anyway, so it doesn't really matter which resolution is used :-)
But think that we should default to usleep still, since nanosleep uses a lot of CPU on certain platforms.

@afbjorklund

Copy link
Copy Markdown
Contributor

I had misunderstood a couple of things. First that the "MSYS" prompt is now a Cygwin environment!
Second was that the two MinGW shells do not really "work" OK, unless you install their toolchains too...

i.e. if you don't populate /mingw32 and /mingw64, then they will also use the default (i.e. Cygwin)
But after installing mingw-w64-i686-gcc and mingw-w64-x86_64-gcc it's all normal again (i.e. MinGW)

Seems to be a lot left to do with portability: https://github.com/TeaCI/tea-ci/wiki/Msys2-on-Wine


But it should be doable (just a couple of bugfixes and bit-rot), to support both MinGW and Cygwin...

The "issue" would be trying to support a more native Windows, with only Visual Studio or something ?
Like porting the build system from autotools to cmake, as discussed. That would be a breaking change.

Running configure with bash and make with gmake sounds like a reasonable workaround meanwhile.

@jd-gascuel

Copy link
Copy Markdown
Author

@afbjorklund this is precisely the point of this pull request. With it, we do have a common ground on which I can propose more stuff and convergence.

I do currently have an AppVeyor image that:

  • Compile ccache with MinGW64's gcc, using MSYS2 emulation layer to have access to linux like environment on windows.
  • Compile ccache with the original Visual 2013 compiler on windows.
  • Compile ccache with the original Visual 2015 compiler on windows.
  • Run for each of them the quick test suite
  • Run for each of them the long test.sh suite with various compilers: gcc, g++ and cc

I am working on having the long test.sh suite work also for Visual compilers (whatever the compiler used to compile ccache). Once done I will be able to propose:

  • a more stable ccache compilation, working better on windows platform with mixed and weird path syntax you get when using native windows environment or various emulation layers above it.
  • a more versatile ccache, able to handle visual options too.

I do not think that using CMake will be an improvement here: I agree with @jrosdahl that having both system is a loss of energy. And as you said, it will be a deep change and have impacts on a lots of people compiling ccache in many environment.
Plus this PR proves that autoconf tools can be used for windows native environment with success too.

Please fill free to ask any changes you thing necessary to process further !

@afbjorklund

afbjorklund commented Apr 7, 2017 •

Copy link
Copy Markdown
Contributor

There's still some things that could be done about readability, like fix your Git settings* (core.autocrlf) to not add those carriage returns ('\r' or ^M) even if you prefer your DOS line endings locally (that is fine).
Indenting your #include's is also not recommended, since it doesn't even work on all platforms/compilers. It's sad that a lot of standard headers (stdbool/inttypes) are missing, but I guess that is portability for ya...

But like I said, MinGW/Cygwin should be fixed already and adding Appveyor/Windows is up to @jrosdahl. Doesn't hurt if the changes are kept minimal anyway, even if it is on a separate branch or a separate fork ?
Adding support for Windows options (/) and Windows paths (C:\) is always going to be lots of code, though. I don't think there's any good way of getting around that, at least not without using something like MSYS...

I do prefer things portable, and thank you for your interest in ccache.

Just not sure if using "real" Windows (without Bash) is ever worth it. :-P

@staticfloat

Copy link
Copy Markdown

Just to add a little +1 for this; I was unable to compile ccache on a ppc64le machine until I updated the config.guess and config.sub files to the same contents as those found in this pull request. I can confirm that it compiled successfully after incorporating these changes.

@jrosdahl jrosdahl added the os: windows Related to building or running on Windows label Jan 31, 2018
jrosdahl added a commit that referenced this pull request Jan 31, 2018
jrosdahl added a commit that referenced this pull request Jan 31, 2018
@jrosdahl

Copy link
Copy Markdown
Member

Note: I've updated config.guess and config.sub to modern versions on master now.

@jrosdahl

Copy link
Copy Markdown
Member

@jd-gascuel: Closing this now due to inactivity. Please resubmit any proposed fixes as new pull requests if you like.

@jrosdahl jrosdahl closed this Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

os: windows Related to building or running on Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants