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

Fix build for clang on windows #259

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/tbox/platform/windows/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
*/
tb_bool_t tb_dns_init_env()
{
// done
FIXED_INFO* info = tb_null;
ULONG size = 0;
tb_size_t count = 0;
FIXED_INFO* info = tb_null;
ULONG size = 0;
do
{
// init func
Expand Down Expand Up @@ -66,7 +64,6 @@ tb_bool_t tb_dns_init_env()

// add the first dns address
tb_dns_server_add(info->DnsServerList.IpAddress.String);
count++;

// walk dns address
IP_ADDR_STRING* addr = info->DnsServerList.Next;
Expand All @@ -77,7 +74,6 @@ tb_bool_t tb_dns_init_env()

// add the dns address
tb_dns_server_add(addr->IpAddress.String);
count++;
}

} while (0);
Expand Down
82 changes: 48 additions & 34 deletions src/tbox/prefix/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@
# error Unknown borland c++ Compiler Version
# endif

// gnu c/c++
#elif defined(__GNUC__)
# define TB_COMPILER_IS_GCC
// gcc or clang
#elif defined(__GNUC__) || defined(__clang__)

# if defined(__MINGW32__) || defined(__MINGW64__)
# define TB_COMPILER_IS_MINGW
# endif
Expand All @@ -142,43 +142,23 @@
defined(TB_COMPILER_ON_MSYS) || defined(TB_COMPILER_ON_CYGWIN)
# define TB_COMPILER_LIKE_UNIX
# endif
# define TB_COMPILER_VERSION_BT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) > ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_BE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) >= ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_EQ(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) == ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_LT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) < ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_LE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) <= ((major) * 100 + (minor)))
# define TB_COMPILER_STRING "gnu c/c++"
# if __GNUC__ == 2
# if __GNUC_MINOR__ < 95
# define TB_COMPILER_VERSION_STRING "gnu c/c++ <2.95"
# elif __GNUC_MINOR__ == 95
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.95"
# elif __GNUC_MINOR__ == 96
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.96"
# else
# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 2.96 && < 3.0"
# endif
# elif __GNUC__ == 3
# if __GNUC_MINOR__ == 2
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.2"
# elif __GNUC_MINOR__ == 3
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.3"
# elif __GNUC_MINOR__ == 4
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.4"
# else
# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 3.4 && < 4.0"
# endif
# elif __GNUC__ >= 4 && defined(__GNUC_MINOR__)
# define TB_COMPILER_VERSION_STRING __tb_mstrcat4__("gnu c/c++ ", __tb_mstring_ex__(__GNUC__), ".", __tb_mstring_ex__(__GNUC_MINOR__))
# else
# error Unknown gnu c/c++ Compiler Version

# if defined(__clang__)
# define TB_COMPILER_IS_CLANG
# endif

// we always need to be compatible with gcc style code if the current compiler is clang
# define TB_COMPILER_IS_GCC

// clang
# if defined(__clang__)
# define TB_COMPILER_IS_CLANG
# undef TB_COMPILER_STRING
# define TB_COMPILER_STRING "clang c/c++"
# define TB_COMPILER_VERSION_BT(major, minor) ((__clang_major__ * 100 + __clang_minor__) > ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_BE(major, minor) ((__clang_major__ * 100 + __clang_minor__) >= ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_EQ(major, minor) ((__clang_major__ * 100 + __clang_minor__) == ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_LT(major, minor) ((__clang_major__ * 100 + __clang_minor__) < ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_LE(major, minor) ((__clang_major__ * 100 + __clang_minor__) <= ((major) * 100 + (minor)))
# if defined(__VERSION__)
# undef TB_COMPILER_VERSION_STRING
# define TB_COMPILER_VERSION_STRING __VERSION__
Expand All @@ -204,6 +184,40 @@
* pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)
*/
# pragma clang diagnostic ignored "-Wnullability-completeness"

// gcc
# elif defined(__GNUC__)
# define TB_COMPILER_VERSION_BT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) > ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_BE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) >= ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_EQ(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) == ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_LT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) < ((major) * 100 + (minor)))
# define TB_COMPILER_VERSION_LE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) <= ((major) * 100 + (minor)))
# define TB_COMPILER_STRING "gnu c/c++"
# if __GNUC__ == 2
# if __GNUC_MINOR__ < 95
# define TB_COMPILER_VERSION_STRING "gnu c/c++ <2.95"
# elif __GNUC_MINOR__ == 95
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.95"
# elif __GNUC_MINOR__ == 96
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.96"
# else
# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 2.96 && < 3.0"
# endif
# elif __GNUC__ == 3
# if __GNUC_MINOR__ == 2
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.2"
# elif __GNUC_MINOR__ == 3
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.3"
# elif __GNUC_MINOR__ == 4
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.4"
# else
# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 3.4 && < 4.0"
# endif
# elif __GNUC__ >= 4 && defined(__GNUC_MINOR__)
# define TB_COMPILER_VERSION_STRING __tb_mstrcat4__("gnu c/c++ ", __tb_mstring_ex__(__GNUC__), ".", __tb_mstring_ex__(__GNUC_MINOR__))
# else
# error Unknown gnu c/c++ Compiler Version
# endif
# endif

// watcom c/c++
Expand Down
2 changes: 1 addition & 1 deletion src/xmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ check_interfaces() {
check_module_cfuncs "posix" "dlfcn.h" "dlopen"
check_module_cfuncs "posix" "sys/stat.h fcntl.h" "open" "stat64" "lstat64"
check_module_cfuncs "posix" "unistd.h" "gethostname"
check_module_cfuncs "posix" "ifaddrs.h" "getifaddrs"
check_module_cfuncs "posix" "ifaddrs.h net/if_dl.h" "getifaddrs"
check_module_cfuncs "posix" "semaphore.h" "sem_init"
check_module_cfuncs "posix" "unistd.h" "getpagesize" "sysconf"
check_module_cfuncs "posix" "sched.h" "sched_yield" "sched_setaffinity" # need _GNU_SOURCE
Expand Down
2 changes: 1 addition & 1 deletion xmake/check_interfaces.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function _check_interfaces(target)
_check_module_cfuncs(target, "posix", "dlfcn.h", "dlopen")
_check_module_cfuncs(target, "posix", {"sys/stat.h", "fcntl.h"}, "open", "stat64", "lstat64")
_check_module_cfuncs(target, "posix", "unistd.h", "gethostname")
_check_module_cfuncs(target, "posix", "ifaddrs.h", "getifaddrs")
_check_module_cfuncs(target, "posix", {"ifaddrs.h", "net/if_dl.h"}, "getifaddrs")
_check_module_cfuncs(target, "posix", "unistd.h", "getpagesize", "sysconf")
_check_module_cfuncs(target, "posix", "sched.h", "sched_yield", "sched_setaffinity") -- need _GNU_SOURCE
_check_module_cfuncs(target, "posix", "regex.h", "regcomp", "regexec")
Expand Down