From 9a2b4ed461562a65e800173208cfab5d4e79d871 Mon Sep 17 00:00:00 2001 From: buty4649 Date: Tue, 17 Oct 2023 00:05:52 +0900 Subject: [PATCH] Changed to use zig for builds on Windows. --- build_config.rb | 22 ++++++++++----------- crossbuild/gai_strerror.c | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 crossbuild/gai_strerror.c diff --git a/build_config.rb b/build_config.rb index f3144b4..615130d 100644 --- a/build_config.rb +++ b/build_config.rb @@ -89,18 +89,9 @@ def build_config(conf, target = nil, strip: false) if build_targets.include?('windows-amd64') MRuby::CrossBuild.new('windows-amd64') do |conf| - toolchain :gcc - - conf.build_target = 'x86_64-pc-linux-gnu' - conf.host_target = 'x86_64-w64-mingw32' - - [conf.cc, conf.linker].each do |cc| - cc.command = "#{ccache}#{conf.host_target}-gcc-posix" - cc.flags << '-static' - end - conf.cc.defines += %w[MRB_STR_LENGTH_MAX=0 MRB_UTF8_STRING MRUBY_YAML_NO_CANONICAL_NULL] - conf.cxx.command = "#{ccache}#{conf.host_target}-g++" - conf.archiver.command = "#{ccache}#{conf.host_target}-gcc-ar" + build_config(conf, 'x86_64-windows', strip: true) + conf.cc.flags << '-lws2_32' + conf.linker.flags << '-lws2_32' conf.exts do |exts| exts.object = '.obj' @@ -108,6 +99,13 @@ def build_config(conf, target = nil, strip: false) exts.library = '.lib' end + crossbuild_root = File.join(build_dir, 'crossbuild') + FileUtils.mkdir_p(crossbuild_root) + crossbuild_lib_path = File.join(crossbuild_root, 'gai_strerror.o') + crossbuild_src_path = File.join(__dir__, 'crossbuild', 'gai_strerror.c') + `#{conf.cc.command} #{conf.cc.flags.join(' ')} -o #{crossbuild_lib_path} -c #{crossbuild_src_path}` + conf.linker.flags << crossbuild_lib_path + debug_config(conf) gem_config(conf) end diff --git a/crossbuild/gai_strerror.c b/crossbuild/gai_strerror.c new file mode 100644 index 0000000..bd09bca --- /dev/null +++ b/crossbuild/gai_strerror.c @@ -0,0 +1,41 @@ +#include +#include + +#ifndef UNICODE +char* gai_strerrorA(int errcode) +{ + static char buf[GAI_STRERROR_BUFFER_SIZE + 1]; + + FormatMessageA( + FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS + | FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, + errcode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, GAI_STRERROR_BUFFER_SIZE + 1, + NULL); + + return buf; +} + +#else + +WCHAR* gai_strerrorW(int errcode) +{ + static WCHAR buf[GAI_STRERROR_BUFFER_SIZE + 1]; + + FormatMessageW( + FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS + | FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, + errcode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, GAI_STRERROR_BUFFER_SIZE + 1, + NULL); + + return buf; +} + +#endif