concurrencykit / ck

Concurrency primitives, safe memory reclamation mechanisms and non-blocking (including lock-free) data structures designed to aid in the research, design and implementation of high performance concurrent systems developed in C99+.
http://concurrencykit.org/
Other
2.34k stars 312 forks source link

How could we cross compile ck? #193

Closed zetalog closed 2 years ago

zetalog commented 2 years ago

It looks the "configure" is a hand-writing script not a script generated by autoconf, and contains the following code:

cat << EOF > .1.c
#include <stdio.h>
int main(void) {
#if defined(_WIN32)
#if defined(__MINGW64__)
    puts("mingw64");
    return (0);
#elif defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION >= 3)
    puts("mingw32");
    return (0);
#else
    return (1);
#endif /* __MINGW32__ && __MINGW32_MAJOR_VERSION >= 3 */
#elif defined(__clang__) && (__clang_major__ >= 3)
    puts("clang");
    return (0);
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5110)
    puts("suncc");
    return (0);
#elif defined(__GNUC__) && (__GNUC__ >= 4)
    puts("gcc");
    return (0);
#else
    return (1);
#endif
}
EOF

$CC -o .1 .1.c
COMPILER=`./.1 2> /dev/null`
r=$?
rm -f .1.c .1

The block is trying to execute a target binary via the following line and definitely will fail:

COMPILER=`./.1 2> /dev/null`

It thus looks like that the "ck" doesn't support cross compile. Am I right? If not, please help to tell how could we cross compile ck.

Thanks in advance.

zetalog commented 2 years ago

Other than this, it looks ck can perfectly support cross compilation. I confirmed that by forcing a COMPILER name here to bypass the detection code.

So please help to fix the issue in the right way in ck upstream. Thanks in advance.

zetalog commented 2 years ago

Related PR: https://github.com/concurrencykit/ck/pull/194

zetalog commented 2 years ago

Below is the patch to bypass COMPILER detection:

Index: ck/configure
===================================================================
--- ck.orig/configure
+++ ck/configure
@@ -657,7 +669,8 @@ if test ! -x "${CC}"; then
 fi
 assert "$CC" "not found"

-cat << EOF > .1.c
+if test "x$COMPILER" = "x"; then
+       cat << EOF > .1.c
 #include <stdio.h>
 int main(void) {
 #if defined(_WIN32)
@@ -685,10 +698,11 @@ int main(void) {
 }
 EOF

-$CC -o .1 .1.c
-COMPILER=`./.1 2> /dev/null`
-r=$?
-rm -f .1.c .1
+       $CC -o .1 .1.c
+       COMPILER=`./.1 2> /dev/null`
+       r=$?
+       rm -f .1.c .1
+fi

 if test "$r" -ne 0; then
        assert "" "update compiler"

This may not be required by upstream if the issue can be properly handled. But if you want, I can also push it to the upstream.

sbahra commented 2 years ago

Thanks for patch!

jscheid-ventana commented 1 year ago

@sbahra, I don't see https://github.com/concurrencykit/ck/issues/193#issuecomment-1162564889 making it into the master branch. https://github.com/concurrencykit/ck/pull/194 did not include it.