forked from elizagamedev/conan-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconanfile.py
186 lines (162 loc) · 7.72 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
from conans import ConanFile, AutoToolsBuildEnvironment, tools
from conans.errors import ConanException
import os.path
import shutil
class RubyConan(ConanFile):
name = "ruby"
version = "2.7.5"
description = "The Ruby Programming Language"
topics = ("conan", "ruby")
url = "https://github.com/GooborgStudios/conan-ruby"
homepage = "https://www.ruby-lang.org"
author = "Gooborg Studios, Eliza Velasquez"
license = "MIT"
settings = "os", "compiler", "build_type", "arch", "arch_build"
extensions = (
"dbm",
"gdbm",
"openssl",
"pty",
"readline",
"syslog",
"zlib"
)
options = {"with_" + extension: [True, False] for extension in extensions}
default_options = {
**{"with_" + extension: False for extension in extensions},
"with_openssl": True,
"with_zlib": True,
"openssl:shared": True,
"zlib:shared": True
}
_source_subfolder = "ruby-{}".format(version)
if tools.os_info.is_windows:
build_requires = "ruby_installer/2.7.3@bincrafters/stable"
def configure(self):
del self.settings.compiler.libcxx
def build_requirements(self):
if tools.os_info.is_windows:
self.build_requires("msys2_installer/20161025@bincrafters/stable")
def requirements(self):
if self.options.with_openssl:
self.requires("openssl/1.1.1l")
if self.options.with_zlib:
self.requires("zlib/1.2.11")
def source(self):
tools.get("https://cache.ruby-lang.org/pub/ruby/{}/{}.tar.gz".format(
self.version.rpartition(".")[0],
self._source_subfolder))
def build_configure(self):
without_ext = (tuple(extension for extension in self.extensions
if not getattr(self.options, "with_" + extension)))
ruby_folder = os.path.join(self.build_folder, self._source_subfolder)
if not os.path.exists(ruby_folder):
self.source()
with tools.chdir(ruby_folder):
if self.settings.compiler == "Visual Studio":
with tools.environment_append({"INCLUDE": self.deps_cpp_info.include_paths,
"LIB": self.deps_cpp_info.lib_paths}):
if self.settings.arch == "x86":
target = "i686-mswin32"
elif self.settings.arch == "x86_64":
target = "x64-mswin64"
else:
raise Exception("Invalid arch")
self.run("{} --prefix={} --target={} --without-ext=\"{},\" --disable-install-doc".format(
os.path.join("win32", "configure.bat"),
self.package_folder,
target,
",".join(without_ext)))
# Patch in runtime settings
def define(line):
tools.replace_in_file(
"Makefile",
"CC = cl -nologo",
"CC = cl -nologo\n" + line)
define("RUNTIMEFLAG = -{}".format(self.settings.compiler.runtime))
if self.settings.build_type == "Debug":
define("COMPILERFLAG = -Zi")
define("OPTFLAGS = -Od -Ob0")
self.run("nmake")
self.run("nmake install")
else:
win_bash = tools.os_info.is_windows
if not win_bash:
without_ext = (*without_ext, 'win32ole', 'win32')
autotools = AutoToolsBuildEnvironment(self, win_bash=win_bash)
# Remove our libs; Ruby doesn't like Conan's help
autotools.libs = []
if self.settings.compiler == "clang":
autotools.link_flags.append("--rtlib=compiler-rt")
args = [
"--with-out-ext=" + ",".join(without_ext),
"--disable-install-doc",
"--without-gmp",
"--enable-shared",
]
if self.options.with_openssl:
openssl_dir = self.deps_cpp_info['openssl'].rootpath
args.append('--with-openssl-dir={}'.format(openssl_dir))
if tools.os_info.is_macos:
# Mitigates an rbinstall linker bug
shutil.copy(os.path.join(openssl_dir, 'lib', 'libssl.1.1.dylib'), './libssl.1.1.dylib')
shutil.copy(os.path.join(openssl_dir, 'lib', 'libcrypto.1.1.dylib'), './libcrypto.1.1.dylib')
if self.options.with_zlib:
zlib_dir = self.deps_cpp_info['zlib'].rootpath
args.append('--with-zlib-dir={}'.format(zlib_dir))
if tools.os_info.is_macos:
# Mitigates an rbinstall linker bug
shutil.copy(os.path.join(zlib_dir, 'lib', 'libz.dylib'), './libz.dylib')
# Mitigate macOS ARM -> x86 cross-compiling bug
make_program = None
if tools.os_info.is_macos and self.settings.arch == "x86_64" and self.settings.arch_build == "armv8":
make_program = 'arch -x86_64 make'
with tools.environment_append(autotools.vars):
# Conan doesn't have a "configure_file" variable, so we have to add the automatically-generated variables ourselves...
cmd = "arch -x86_64 ./configure {} --prefix={}".format(' '.join(args), self.package_folder)
self.output.info("Calling:\n > {}".format(cmd))
self.run(cmd)
else:
autotools.configure(args=args)
autotools.make(['miniruby'], make_program)
autotools.make(make_program=make_program)
autotools.install(make_program=make_program)
def build(self):
if tools.os_info.is_windows:
msys_bin = self.deps_env_info["msys2_installer"].MSYS_BIN
# Make sure that Ruby is first in the path order
path = self.deps_env_info["ruby_installer"].path + [msys_bin]
with tools.environment_append({"PATH": path,
"CONAN_BASH_PATH": os.path.join(msys_bin, "bash.exe")}):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self.settings):
self.build_configure()
else:
self.build_configure()
else:
self.build_configure()
def package_info(self):
# Find correct lib (shared)
libname = None
for f in os.listdir("lib"):
name, ext = os.path.splitext(f)
if ext in (".so", ".lib", ".a", ".dylib"):
if ext != ".lib" and name.startswith("lib"):
name = name[3:]
if not name.endswith("-static"):
libname = name
break
if not libname:
raise ConanException("Could not find built shared library")
self.cpp_info.libs = [libname]
# Find include config dir
includedir = os.path.join("include", "ruby-2.7.0")
configdir = None
for f in os.listdir(os.path.join(self.package_folder, includedir)):
if "mswin" in f or "mingw" in f or "linux" in f or "darwin" in f:
configdir = f
break
if not includedir:
raise Exception("Could not find Ruby config dir")
self.cpp_info.includedirs = [includedir,
os.path.join(includedir, configdir)]