Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit d00f9f2

Browse files
committed
Merge pull request #166 from jarredholman/mingw
Added support for windows platforms using mingw.
2 parents 8f8e205 + 59f0250 commit d00f9f2

6 files changed

Lines changed: 170 additions & 9 deletions

File tree

Rakefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ task :checkout do
2121
end
2222

2323
desc "compile v8 via the ruby extension mechanism"
24-
task :compile do
24+
task :compile => :devkit do
2525
sh "ruby ext/libv8/extconf.rb"
2626
end
2727

@@ -77,5 +77,15 @@ task :clean do
7777
sh "cd #{GYP_Source} && git checkout -f && git clean -dxf"
7878
end
7979

80+
task :devkit do
81+
begin
82+
if RUBY_PLATFORM =~ /mingw/
83+
require "devkit"
84+
end
85+
rescue LoadError => e
86+
abort "Failed to activate RubyInstaller's DevKit required for compilation."
87+
end
88+
end
89+
8090
task :default => [:checkout, :compile, :spec]
8191
task :build => [:clean, :checkout]

appveyor.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: 3.16.14.8.b{build}
2+
3+
# Operating system (build VM template)
4+
os: Windows Server 2012
5+
6+
clone_depth: 10
7+
8+
environment:
9+
matrix:
10+
- ruby_version: "22-x64"
11+
- ruby_version: "22"
12+
- ruby_version: "21-x64"
13+
- ruby_version: "21"
14+
- ruby_version: "200-x64"
15+
- ruby_version: "200"
16+
- ruby_version: "193"
17+
18+
# scripts that run after cloning repository
19+
install:
20+
- set PATH=C:\Ruby%ruby_version%\bin;%PATH%
21+
- git submodule update --init
22+
- ruby --version
23+
- gem --version
24+
- gem install bundler --no-ri --no-rdoc
25+
- bundle --version
26+
- bundle install --jobs=1 --retry=3
27+
28+
build_script:
29+
- bundle exec rake binary
30+
31+
test_script:
32+
- bundle exec rake spec
33+
34+
artifacts:
35+
- path: pkg\*.gem
36+

ext/libv8/builder.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ def initialize
1616
@compiler = choose_compiler
1717
end
1818

19-
def make_flags(*flags)
19+
def make_target
2020
profile = enable_config('debug') ? 'debug' : 'release'
21-
21+
"#{libv8_arch}.#{profile}"
22+
end
23+
24+
def make_flags(*flags)
2225
# FreeBSD uses gcc 4.2 by default which leads to
2326
# compilation failures due to warnings about aliasing.
2427
# http://svnweb.freebsd.org/ports/head/lang/v8/Makefile?view=markup
@@ -42,7 +45,7 @@ def make_flags(*flags)
4245
# with it on
4346
flags << 'werror=no'
4447

45-
"#{libv8_arch}.#{profile} #{flags.join ' '}"
48+
"#{make_target} #{flags.join ' '}"
4649
end
4750

4851
def build_libv8!
@@ -53,7 +56,17 @@ def build_libv8!
5356
setup_build_deps!
5457
patch! *patch_directories_for(@compiler)
5558
print_build_info
56-
puts `env CXX=#{@compiler} LINK=#{@compiler} #{make} #{make_flags}`
59+
60+
case RUBY_PLATFORM
61+
when /mingw/
62+
# use a script that will fix the paths in the generated Makefiles
63+
# don't use make_flags otherwise it will trigger a rebuild of the Makefiles
64+
system "env CXX=#{@compiler} LINK=#{@compiler} bash #{PATCH_DIRECTORY}/mingw-generate-makefiles.sh"
65+
system "env CXX=#{@compiler} LINK=#{@compiler} make #{make_target}"
66+
67+
else
68+
puts `env CXX=#{@compiler} LINK=#{@compiler} #{make} #{make_flags}`
69+
end
5770
end
5871
return $?.exitstatus
5972
end
@@ -96,8 +109,8 @@ def choose_compiler
96109
end
97110

98111
def python_version
99-
if system 'which python 2>&1 > /dev/null'
100-
`python -c 'import platform; print(platform.python_version())'`.chomp
112+
if `which python` =~ /python/
113+
`python -c "import platform; print(platform.python_version())"`.chomp
101114
else
102115
"not available"
103116
end

ext/libv8/checkout.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def checkout!
1515

1616
Dir.chdir(V8_Source) do
1717
`git fetch`
18-
`git checkout #{Libv8::VERSION.gsub(/\.\d+$/,'')} -f`
18+
`git checkout #{Libv8::VERSION.gsub(/\.\d+(\.rc\d+)?$/,'')} -f`
1919
`rm -f .applied_patches`
2020
end
2121

@@ -31,7 +31,8 @@ def checkout!
3131
# --git-dir is needed for older versions of git and git-svn
3232
`git --git-dir=../../.git/modules/vendor/gyp/ svn init #{GYP_SVN} -Ttrunk`
3333
`git config --replace-all svn-remote.svn.fetch trunk:refs/remotes/origin/master`
34-
`git checkout $(git --git-dir=../../.git/modules/vendor/gyp/ svn find-rev r#{rev} | tail -n 1) -f`
34+
svn_rev = `git --git-dir=../../.git/modules/vendor/gyp/ svn find-rev r#{rev} | tail -n 1`
35+
`git checkout #{svn_rev} -f`
3536
end
3637
end
3738

@@ -40,6 +41,9 @@ def git?(dir)
4041
end
4142

4243
def check_git_svn!
44+
# msysgit provides git svn
45+
return if RUBY_PLATFORM =~ /mingw/
46+
4347
unless system 'git help svn 2>&1 > /dev/null'
4448
fail "git-svn not installed!\nPlease install git-svn."
4549
end

ext/libv8/patcher.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def patch!(*additional_directories)
4747

4848
(available_patches - applied_patches).each do |patch|
4949
`patch -p1 -N < #{patch}`
50+
fail 'failed to apply patch' unless $?.success?
5051
f.puts patch
5152
end
5253
end
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/sh
2+
# Copyright 2013 the V8 project authors. All rights reserved.
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are
5+
# met:
6+
#
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above
10+
# copyright notice, this list of conditions and the following
11+
# disclaimer in the documentation and/or other materials provided
12+
# with the distribution.
13+
# * Neither the name of Google Inc. nor the names of its
14+
# contributors may be used to endorse or promote products derived
15+
# from this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
# Monkey-patch GYP.
30+
cat > build/gyp/gyp.mingw << EOF
31+
#!/usr/bin/env python
32+
33+
# Copyright (c) 2009 Google Inc. All rights reserved.
34+
# Use of this source code is governed by a BSD-style license that can be
35+
# found in the LICENSE file.
36+
37+
import sys
38+
39+
# TODO(mark): sys.path manipulation is some temporary testing stuff.
40+
try:
41+
import gyp
42+
except ImportError, e:
43+
import os.path
44+
sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), 'pylib'))
45+
import gyp
46+
47+
def MonkeyBuildFileTargets(target_list, build_file):
48+
"""From a target_list, returns the subset from the specified build_file.
49+
"""
50+
build_file = build_file.replace('/', '\\\\')
51+
return [p for p in target_list if gyp.common.BuildFile(p) == build_file]
52+
gyp.common.BuildFileTargets = MonkeyBuildFileTargets
53+
54+
import gyp.generator.make
55+
import os
56+
def Monkey_ITIP(self):
57+
"""Returns the location of the final output for an installable target."""
58+
sep = os.path.sep
59+
# Xcode puts shared_library results into PRODUCT_DIR, and some gyp files
60+
# rely on this. Emulate this behavior for mac.
61+
if (self.type == 'shared_library' and
62+
(self.flavor != 'mac' or self.toolset != 'target')):
63+
# Install all shared libs into a common directory (per toolset) for
64+
# convenient access with LD_LIBRARY_PATH.
65+
return '\$(builddir)%slib.%s%s%s' % (sep, self.toolset, sep, self.alias)
66+
return '\$(builddir)' + sep + self.alias
67+
gyp.generator.make.MakefileWriter._InstallableTargetInstallPath = Monkey_ITIP
68+
69+
if __name__ == '__main__':
70+
sys.exit(gyp.main(sys.argv[1:]))
71+
EOF
72+
73+
# Delete old generated Makefiles.
74+
find out -name '*.mk' -or -name 'Makefile*' -exec rm {} \;
75+
76+
# Generate fresh Makefiles.
77+
mv build/gyp/gyp build/gyp/gyp.original
78+
mv build/gyp/gyp.mingw build/gyp/gyp
79+
make out/Makefile.ia32 out/Makefile.x64
80+
mv build/gyp/gyp build/gyp/gyp.mingw
81+
mv build/gyp/gyp.original build/gyp/gyp
82+
83+
# Patch generated Makefiles: replace most backslashes with forward slashes,
84+
# fix library names in linker flags.
85+
FILES=$(find out -name '*.mk' -or -name 'Makefile*')
86+
for F in $FILES ; do
87+
echo "Patching $F..."
88+
cp $F $F.orig
89+
cat $F.orig \
90+
| sed -e 's|\([)a-zA-Z0-9]\)\\\([a-zA-Z]\)|\1/\2|g' \
91+
-e 's|\([)a-zA-Z0-9]\)\\\\\([a-zA-Z]\)|\1/\2|g' \
92+
-e 's|'%s/n'|'%s\\\\n'|g' \
93+
-e 's|-lwinmm\.lib|-lwinmm|g' \
94+
-e 's|-lws2_32\.lib|-lws2_32|g' \
95+
> $F
96+
rm $F.orig
97+
done

0 commit comments

Comments
 (0)