Skip to content

Commit 7361d24

Browse files
committed
Build on Windows with WinHTTP
Insert the right libraries to link to to get WinHTTP working. These are normally done by the build system, but we're building statically so we put them in ourselves. We don't write out any dependencies to pkg-config, so let's get rid of it. To boot, it's not always installed on this platform.
1 parent 97d1699 commit 7361d24

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

ext/rugged/extconf.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def sys(cmd)
1515
ret
1616
end
1717

18+
def on_windows
19+
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
20+
end
21+
1822
if !(MAKE = find_executable('gmake') || find_executable('make'))
1923
abort "ERROR: GNU make is required to build Rugged."
2024
end
@@ -55,7 +59,7 @@ def sys(cmd)
5559
abort "ERROR: CMake is required to build Rugged."
5660
end
5761

58-
if !find_executable('pkg-config')
62+
if !on_windows && !find_executable('pkg-config')
5963
abort "ERROR: pkg-config is required to build Rugged."
6064
end
6165

@@ -66,8 +70,16 @@ def sys(cmd)
6670
sys("cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Unix Makefiles\"")
6771
sys(MAKE)
6872

69-
pcfile = File.join(LIBGIT2_DIR, "build", "libgit2.pc")
70-
$LDFLAGS << " " + `pkg-config --libs --static #{pcfile}`.strip
73+
# "normal" libraries (and libgit2 builds) get all these when they build but we're doing it
74+
# statically so we put the libraries in by hand. It's important that we put the libraries themselves
75+
# in $LIBS or the final linking stage won't pick them up
76+
if on_windows
77+
$LDFLAGS << " " + "-L#{Dir.pwd}/deps/winhttp"
78+
$LIBS << " -lwinhttp -lcrypt32 -lrpcrt4 -lole32"
79+
else
80+
pcfile = File.join(LIBGIT2_DIR, "build", "libgit2.pc")
81+
$LDFLAGS << " " + `pkg-config --libs --static #{pcfile}`.strip
82+
end
7183
end
7284
end
7385

0 commit comments

Comments
 (0)