Issue #9189 has been updated by Heesob Park.


I still failed to build trunk.

~~~
C:\work\ruby-2.2.0-r45738>nmake
...
generating psych-x64-mswin64_120.def
compiling psych.c
psych.c
compiling psych_emitter.c
psych_emitter.c
compiling psych_parser.c
psych_parser.c
compiling psych_to_ruby.c
psych_to_ruby.c
compiling psych_yaml_tree.c
psych_yaml_tree.c
compiling ../.././ext/psych/yaml/api.c
api.c
../.././ext/psych/yaml/api.c(10) : error C2491: 'yaml_get_version_string' :definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(11) : error C2065: 'YAML_VERSION_STRING' : undeclared identifier
../.././ext/psych/yaml/api.c(11) : warning C4047: 'return' : 'const char *'differs in levels of indirection from 'int'
../.././ext/psych/yaml/api.c(20) : error C2491: 'yaml_get_version' : definitionof dllimport function not allowed
../.././ext/psych/yaml/api.c(21) : error C2065: 'YAML_VERSION_MAJOR' : undeclared identifier
../.././ext/psych/yaml/api.c(22) : error C2065: 'YAML_VERSION_MINOR' : undeclared identifier
../.././ext/psych/yaml/api.c(23) : error C2065: 'YAML_VERSION_PATCH' : undeclared identifier
../.././ext/psych/yaml/api.c(32) : error C2491: 'yaml_malloc' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(42) : error C2491: 'yaml_realloc' : definitionof dllimport function not allowed
../.././ext/psych/yaml/api.c(52) : error C2491: 'yaml_free' : definition ofdllimport function not allowed
../.././ext/psych/yaml/api.c(62) : error C2491: 'yaml_strdup' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(76) : error C2491: 'yaml_string_extend' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(98) : error C2491: 'yaml_string_join' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(119) : error C2491: 'yaml_stack_extend' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(137) : error C2491: 'yaml_queue_extend' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(172) : error C2491: 'yaml_parser_initialize' :definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(215) : error C2491: 'yaml_parser_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(285) : error C2491: 'yaml_parser_set_input_string': definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(304) : error C2491: 'yaml_parser_set_input_file' :definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(322) : error C2491: 'yaml_parser_set_input' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(337) : error C2491: 'yaml_parser_set_encoding': definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(350) : error C2491: 'yaml_emitter_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(387) : error C2491: 'yaml_emitter_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(453) : error C2491: 'yaml_emitter_set_output_string' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(473) : error C2491: 'yaml_emitter_set_output_file': definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(491) : error C2491: 'yaml_emitter_set_output' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(506) : error C2491: 'yaml_emitter_set_encoding' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(519) : error C2491: 'yaml_emitter_set_canonical' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(531) : error C2491: 'yaml_emitter_set_indent' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(543) : error C2491: 'yaml_emitter_set_width' :definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(555) : error C2491: 'yaml_emitter_set_unicode': definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(567) : error C2491: 'yaml_emitter_set_break' :definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(579) : error C2491: 'yaml_token_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(665) : error C2491: 'yaml_stream_start_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(681) : error C2491: 'yaml_stream_end_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(701) : error C2491: 'yaml_document_start_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(776) : error C2491: 'yaml_document_end_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(792) : error C2491: 'yaml_alias_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(820) : error C2491: 'yaml_scalar_event_initialize': definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(876) : error C2491: 'yaml_sequence_start_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(913) : error C2491: 'yaml_sequence_end_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(931) : error C2491: 'yaml_mapping_start_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(968) : error C2491: 'yaml_mapping_end_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(984) : error C2491: 'yaml_event_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1039) : error C2491: 'yaml_document_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1122) : error C2491: 'yaml_document_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1169) : error C2491: 'yaml_document_get_node' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1184) : error C2491: 'yaml_document_get_root_node' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1201) : error C2491: 'yaml_document_add_scalar' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1259) : error C2491: 'yaml_document_add_sequence' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1309) : error C2491: 'yaml_document_add_mapping' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1359) : error C2491: 'yaml_document_append_sequence_item' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1387) : error C2491: 'yaml_document_append_mapping_pair' : definition of dllimport function not allowed
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio12.0\VC\BIN\x86_amd64\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio12.0\VC\BIN\nmake.EXE"' : return code '0x2'
Stop.
~~~

Here is a patch.

~~~
diff --git a/hash.c b/hash.c
index c3a06e5..64c4057 100644
--- a/hash.c
+++ b/hash.c.new
@@ -2740,7 +2740,13 @@ ruby_setenv(const char *name, const char *value)
     else {
 	buf = rb_sprintf("%s=", name);
     }
-    failed = putenv(RSTRING_PTR(buf));
+    if(rb_locale_encindex()==ENCINDEX_ASCII) {
+        WCHAR *wbuf = rb_w32_mbstr_to_wstr(CP_UTF8, RSTRING_PTR(buf), -1, NULL);     
+        failed = _wputenv(wbuf);
+        free(wbuf);
+    } else {
+        failed = putenv(RSTRING_PTR(buf)); 
+    }     
     /* even if putenv() failed, clean up and try to delete the
      * variable from the system area. */
     rb_str_resize(buf, 0); 
~~~
     

----------------------------------------
Bug #9189: Build failure on Windows in case of nonascii TEMP environment.
https://bugs.ruby-lang.org/issues/9189#change-46365

* Author: Heesob Park
* Status: Assigned
* Priority: Normal
* Assignee: 
* Category: 
* Target version: current: 2.2.0
* ruby -v: ruby 2.1.0dev (2013-11-30 trunk 43936) [i386-mingw32]
* Backport: 1.9.3: DONTNEED, 2.0.0: REQUIRED
----------------------------------------
I experienced a build failure during build extension library with trunk on Windows.

	make[2]: Entering directory `/c/work/ruby-2.1.0-r43936/ext/bigdecimal'
	generating bigdecimal-i386-mingw32.def
	compiling bigdecimal.c
	In file included from bigdecimal.c:20:0:
	bigdecimal.h:62:1: error: static declaration of 'labs' follows non-static declar
	ation
	make[2]: *** [bigdecimal.o] Error 1
	make[2]: Leaving directory `/c/work/ruby-2.1.0-r43936/ext/bigdecimal'
	make[1]: *** [ext/bigdecimal/all] Error 2
	make[1]: Leaving directory `/c/work/ruby-2.1.0-r43936'
	make: *** [build-ext] Error 2

I found the cause of this error is mkmk failure.
Here is a part of mkmf.log

	have_func: checking for labs() in stdlib.h... -------------------- no

	"i686-w64-mingw32-gcc -o conftest.exe -I../../.ext/include/i386-mingw32 -I../.././include -I../.././ext/bigdecimal -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -L../.. -L.      -lmsvcrt-ruby210-static  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "

	This application has requested the Runtime to terminate it in an unusual way.
	Please contact the application's support team for more information.
	Cannot create temporary file in C:\Users\???AppData\Local\Temp\: Invalid argument


The TEMP environment varable is
	
	C:\work\ruby-2.1.0-r43936>set TEMP
	TEMP=C:\Users\\AppData\Local\Temp

It seems that miniruby cannot handle encoding properly.
	
	C:\work\ruby-2.1.0-r43936>miniruby -ve "p ENV['TEMP']"
	ruby 2.1.0dev (2013-11-30 trunk 43936) [i386-mingw32]
	"C:\\Users\\\xED\x9D\xAC\xEC\x84\xAD\\AppData\\Local\\Temp"

	C:\work\ruby-2.1.0-r43936>miniruby.exe -ve "p ENV['TEMP'].encoding"
	ruby 2.1.0dev (2013-11-30 trunk 43936) [i386-mingw32]
	#<Encoding:ASCII-8BIT>	
	
Whereas, the final ruby can handle encoding properly.

	C:\work>ruby -ve "p ENV['TEMP']"
	ruby 2.1.0dev (2013-11-30 trunk 43923) [i386-mingw32]
	"C:\\Users\\\\AppData\\Local\\Temp"	

	C:\work>ruby -ve "p ENV['TEMP'].encoding"
	ruby 2.1.0dev (2013-11-30 trunk 43923) [i386-mingw32]
	#<Encoding:CP949>




-- 
https://bugs.ruby-lang.org/