Skip to content

Commit

Permalink
Changed to use zig for builds on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
buty4649 committed Oct 16, 2023
1 parent 4b74277 commit 9a2b4ed
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
22 changes: 10 additions & 12 deletions build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,23 @@ 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'
exts.executable = '.exe'
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
Expand Down
41 changes: 41 additions & 0 deletions crossbuild/gai_strerror.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <winsock2.h>
#include <ws2tcpip.h>

#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

0 comments on commit 9a2b4ed

Please sign in to comment.