@@ -119,22 +119,40 @@ def install_with_worker
119119 end
120120
121121 def with_jobserver
122- r , w = IO . pipe
123- r . close_on_exec = false
124- w . close_on_exec = false
125- w . write ( "*" * @size )
126-
127- old_makeflags = ENV [ "MAKEFLAGS" ]
128- ENV [ "MAKEFLAGS" ] = [ old_makeflags , "--jobserver-auth=#{ r . fileno } ,#{ w . fileno } " ] . compact . join ( " " )
129-
130- yield
131- ensure
132- # Restore MAKEFLAGS before closing the pipe so a close failure can't
133- # leave the process with descriptors that point at a closed pipe.
134- old_makeflags ? ENV [ "MAKEFLAGS" ] = old_makeflags : ENV . delete ( "MAKEFLAGS" )
122+ # The jobserver hands tokens to child `make` processes through MAKEFLAGS
123+ # using the GNU make `--jobserver-auth` protocol. nmake, the default make
124+ # on mswin, instead reads MAKEFLAGS as bare option letters and aborts
125+ # every native extension build with `fatal error U1065: invalid option
126+ # '-'`. Skip the jobserver when nmake is in use. Other Windows toolchains
127+ # such as mingw use GNU make and keep working through the inherited pipe.
128+ return yield if nmake?
129+
130+ begin
131+ r , w = IO . pipe
132+ r . close_on_exec = false
133+ w . close_on_exec = false
134+ w . write ( "*" * @size )
135+
136+ old_makeflags = ENV [ "MAKEFLAGS" ]
137+ ENV [ "MAKEFLAGS" ] = [ old_makeflags , "--jobserver-auth=#{ r . fileno } ,#{ w . fileno } " ] . compact . join ( " " )
138+
139+ yield
140+ ensure
141+ # Restore MAKEFLAGS before closing the pipe so a close failure can't
142+ # leave the process with descriptors that point at a closed pipe.
143+ old_makeflags ? ENV [ "MAKEFLAGS" ] = old_makeflags : ENV . delete ( "MAKEFLAGS" )
144+
145+ r &.close
146+ w &.close
147+ end
148+ end
135149
136- r &.close
137- w &.close
150+ # Mirror how RubyGems' extension builder picks the make program so the
151+ # jobserver is only set up when a GNU-compatible make will consume it.
152+ def nmake?
153+ make = ENV [ "MAKE" ] || ENV [ "make" ]
154+ make ||= "nmake" if RUBY_PLATFORM . include? ( "mswin" )
155+ /\b nmake/i . match? ( make . to_s )
138156 end
139157
140158 def install_serially
0 commit comments