如何在 Mac OS X 上手动构建通用 ruby​​?用rvm怎么样?

发布于 2024-09-07 09:25:01 字数 1224 浏览 4 评论 0原文

我从 官方 git 镜像 获取了 ruby​​ 源代码,然后查看了 ruby_1_9_2 分支机构。

git clone http://github.com/ruby/ruby.git
git checkout ruby_1_9_2

所以,现在我想编译 1.9.2-head。但正如您稍后将看到的,我希望有一个也适用于 1.8 的解决方案。

编译这个的标准方法是:

autoconf
./configure
make
make install

这可行,但它产生了一个仅限 x86_64 的版本:

$ ruby -v
ruby 1.9.2dev (2010-06-14 revision 28321) [x86_64-darwin10.3.0]

显然,我不关心 PPC,因为我使用的是 10.6,但我想同时拥有 i386 和 x86_64,因为 < a href="http://rubyforge.org/pipermail/rb-appscript-discuss/2010-May/000343.html" rel="nofollow noreferrer">有些事情需要在32位中完成。

所以,我想知道的是:

  1. 构建具有 i386 和 x86_64 架构的胖二进制文件的魔法。
  2. 我也有兴趣对我的 RVM ruby​​ 版本做同样的事情。

可能不必要的系统信息:

$ system_profiler -detailLevel mini SPSoftwareDataType | ack '^ {6}' | head -3
      System Version: Mac OS X 10.6.4 (10F569)
      Kernel Version: Darwin 10.4.0
      64-bit Kernel and Extensions: No

$ uname -a
Darwin meaningless.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386

I got the ruby sources from the official git mirror, then checked out the ruby_1_9_2 branch.

git clone http://github.com/ruby/ruby.git
git checkout ruby_1_9_2

So, for now, I want to compile 1.9.2-head. But as you'll see later I'm hoping for a solution that works for 1.8 too.

The standard way to compile this is:

autoconf
./configure
make
make install

That works, but it yields me a x86_64-only build:

$ ruby -v
ruby 1.9.2dev (2010-06-14 revision 28321) [x86_64-darwin10.3.0]

I don't care about PPC, obviously, since I'm on 10.6, but I want to have both i386 and x86_64, because some things need to be done in 32-bit.

So, what I want to know:

  1. the magic chants to build a fat binary with both i386 and x86_64 archs.
  2. I would also be interested in doing the same with my RVM ruby versions.

Probably unecessary system information:

$ system_profiler -detailLevel mini SPSoftwareDataType | ack '^ {6}' | head -3
      System Version: Mac OS X 10.6.4 (10F569)
      Kernel Version: Darwin 10.4.0
      64-bit Kernel and Extensions: No

$ uname -a
Darwin meaningless.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

π浅易 2024-09-14 09:25:17

至于 RVM,它说你不能拥有胖二进制文件,但事实并非如此,因为包含 我的补丁

使用最新的 rvm,您可以使用与手动构建中相同的配置标志来安装 ruby​​-1.9.2-head:

$ rvm install ruby-1.9.2-head -C --with-arch=x86_64,i386

证明它应该有效:

$ rvm use 1.9.2-head
info: Using ruby 1.9.2 head

$ file `which ruby` | perl -pe 's|^.*/||'
ruby: Mach-O universal binary with 2 architectures
ruby (for architecture x86_64): Mach-O 64-bit executable x86_64
ruby (for architecture i386):   Mach-O executable i386

As for RVM, it says you can't have fat binaries, but that's not true as of this commit which incorporates my patch.

Using the latest rvm you can install ruby-1.9.2-head using the same configure flag as in the manual build:

$ rvm install ruby-1.9.2-head -C --with-arch=x86_64,i386

Proof that it's supposedly working:

$ rvm use 1.9.2-head
info: Using ruby 1.9.2 head

$ file `which ruby` | perl -pe 's|^.*/||'
ruby: Mach-O universal binary with 2 architectures
ruby (for architecture x86_64): Mach-O 64-bit executable x86_64
ruby (for architecture i386):   Mach-O executable i386
愁以何悠 2024-09-14 09:25:15

./configure 中使用 --with-arch 选项:

$ ./configure --with-arch=x86_64,i386

--with-arch 采用逗号分隔的 Ruby 架构列表应该建造。


由 kch 添加:

成功构建后的输出:

$ file ruby
ruby: Mach-O universal binary with 2 architectures
ruby (for architecture x86_64): Mach-O 64-bit executable x86_64
ruby (for architecture i386):   Mach-O executable i386

$ arch -i386 ./ruby -v
ruby 1.9.2dev (2010-06-29 revision 28468) [universal.i386-darwin10.4.0]

$ arch -x86_64 ./ruby -v
ruby 1.9.2dev (2010-06-29 revision 28468) [universal.x86_64-darwin10.4.0]

$ ./ruby -v
ruby 1.9.2dev (2010-06-29 revision 28468) [universal.x86_64-darwin10.4.0]

Use the --with-arch option to ./configure:

$ ./configure --with-arch=x86_64,i386

--with-arch takes a comma-separated list of architectures for which Ruby should be built.


added by kch:

Output after a successful build:

$ file ruby
ruby: Mach-O universal binary with 2 architectures
ruby (for architecture x86_64): Mach-O 64-bit executable x86_64
ruby (for architecture i386):   Mach-O executable i386

$ arch -i386 ./ruby -v
ruby 1.9.2dev (2010-06-29 revision 28468) [universal.i386-darwin10.4.0]

$ arch -x86_64 ./ruby -v
ruby 1.9.2dev (2010-06-29 revision 28468) [universal.x86_64-darwin10.4.0]

$ ./ruby -v
ruby 1.9.2dev (2010-06-29 revision 28468) [universal.x86_64-darwin10.4.0]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文