知行编程网知行编程网  2022-07-22 11:00 知行编程网 隐藏边栏 |   抢沙发  420 
文章评分 0 次,平均分 0.0

程序员用 M1 MacBook 当主力开发机​是什么体验?

来自 | 量子位

程序员用 M1 MacBook 当主力开发机​是什么体验?
MacBook 换成 ARM 芯片后,它还是程序员的开发利器吗?
经过国外程序员半个多月来的尝试,一些常见开发工具的兼容状况也得到披露。
Xcode、VS Code、Homebrew…… 等常用工具能够完美运行吗?如果你还在因为这些问题犹豫要不要买,那么看了这篇文章或许能得到答案。

   代码编辑器

Vim 是通用二进制文件,因此它已经能在 M1 上直接运行。
VS Code 可以通过 Rosetta 2 转换来运行,而 insider 版已经原生支持 ARM 平台的 MacBook,相信正式版也不会太遥远。
程序员用 M1 MacBook 当主力开发机​是什么体验?

   Xcode

苹果第一方开发工具 Xcode 自然不必担心兼容性,而且它在 M1 芯片上的运行效率很高。
编译 PSPDFKit PDF SDK,在 2019 年 16 英寸 MacBook Pro 上耗时 7 分 31 秒,在 M1 版 MacBook Air 上则耗时 8 分 49 秒,而后者是无风扇的。
不过 Xcode 在测试低于 iOS 14 版的应用程序时,会出现一些问题。WebKit 会在内存分配器中崩溃,Xcode 有时会定期卡死。
程序员用 M1 MacBook 当主力开发机​是什么体验?
因此如果你要测试较低 iOS 版本程序,还是在 Intel 版的 MacBook 上运行,或者希望下一次 Xcode 更新时,苹果能解决这个问题。

   Docker

现在 Docker 无法在 M1 芯片上运行,也无法通过 Rosetta 2 转换的方式使用 Docker Desktop。
但是同样使用 ARM 芯片的树莓派却能做到。
程序员用 M1 MacBook 当主力开发机​是什么体验?

所以在 MacBook 上运行 Docker 最好的方法是:运行 ARM 版 Linux 虚拟机,在虚拟机中运行 Docker。
具体操作方法请参照这篇教程:
https://finestructure.co/blog/2020/11/27/running-docker-on-apple-silicon-m1
至于 Docker 官方何时将提供支持,可以注册 Docker ID 来获取最新进展。

   Homebrew

Homebrew 可以通过 Rosetta 2 转换的方式进行安装,方法也很简单,只需在过去的安装命令前加上 arch -x86_64 即可。
<section style="padding: 0.5em;line-height: 18px;font-size: 14px;letter-spacing: 0px;font-family: Consolas, Inconsolata, Courier, monospace;border-radius: 0px;color: rgb(169, 183, 198);background-color: rgb(40, 43, 46);margin-left: 8px;margin-right: 8px;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;"><span style="font-size: 15px;">$ arch -x86_64 /bin/bash -c <span style="line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"<span style="line-height: inherit;color: rgb(98, 151, 85);">$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)</span>"</span><br  /></span></section>
这种通过转制的 Homebrew 在某些软件上可能有一些兼容性问题,因此建议安装另一个手动编译版:
<section style="padding: 0.5em;line-height: 18px;font-size: 14px;letter-spacing: 0px;font-family: Consolas, Inconsolata, Courier, monospace;border-radius: 0px;color: rgb(169, 183, 198);background-color: rgb(40, 43, 46);margin-left: 8px;margin-right: 8px;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;"><span style="font-size: 15px;">$ sudo mkdir -p /opt/homebrew<br  />$ sudo chown -R $(whoami):staff /opt/homebrew<br  />$ <span style="line-height: inherit;color: rgb(248, 35, 117);overflow-wrap: inherit !important;word-break: inherit !important;">cd</span> /opt<br  />$ curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew<br  /></span></section>

第一种方式安装的 Homebrew 在 /usr/local/bin 目录下,而第二种方式安装的在 /opt/homebrew 目录下,后者不会自动添加到 PATH 环境变量中,因此需要手动设置:
<section style="padding: 0.5em;line-height: 18px;font-size: 14px;letter-spacing: 0px;font-family: Consolas, Inconsolata, Courier, monospace;border-radius: 0px;color: rgb(169, 183, 198);background-color: rgb(40, 43, 46);margin-left: 8px;margin-right: 8px;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;"><span style="font-size: 15px;"><span style="line-height: inherit;color: rgb(248, 35, 117);overflow-wrap: inherit !important;word-break: inherit !important;">export</span> PATH=<span style="line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">"/opt/homebrew/bin:<span style="line-height: inherit;color: rgb(98, 151, 85);">$PATH</span>"</span><br  /></span></section>

这样,你的 Mac 里就有了两个 Homebrew:一个是 Rosetta 转换的,一个是原生的。原生的目录在前面,那么 brew 命令将默认运行这个版本。
如果想运行 Rosetta 转换版怎么办?我们可以单独设置一个 ibrew 命令:
<section style="padding: 0.5em;line-height: 18px;font-size: 14px;letter-spacing: 0px;font-family: Consolas, Inconsolata, Courier, monospace;border-radius: 0px;color: rgb(169, 183, 198);background-color: rgb(40, 43, 46);margin-left: 8px;margin-right: 8px;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;"><span style="font-size: 15px;"><span style="line-height: inherit;color: rgb(248, 35, 117);overflow-wrap: inherit !important;word-break: inherit !important;">alias</span> ibrew=<span style="line-height: inherit;color: rgb(238, 220, 112);overflow-wrap: inherit !important;word-break: inherit !important;">'arch -x86_64 /usr/local/bin/brew'</span><br  /></span></section>

目前,Homebrew 尚未提供用于 ARM Mac 的预编译软件包,因此最好使用 brew install -s 命令进行安装。
具体有哪些软件包不兼容,可以到 GitHub 项目页的 issue 中查询:
https://github.com/Homebrew/brew/issues/7857

   其他常用软件

说到编程必备,怎么能少得了 Chrome,现在 Chrome 87 版已经开始支持 M1 版的 MacBook。
程序员用 M1 MacBook 当主力开发机​是什么体验?
还有微软的 Office 三件套,若使用 Rosetta 2 转译,启动时间可能需要 20 秒。官方建议安装针对 macOS Big Sur 优化的 16.43 版。
微软官方表示,已经开始将 Mac 应用程序迁移到通用二进制文件,未来 Office 三件套的兼容性不成问题。
如果是基于 Electron 的应用程序,经过 Rosetta 2 转译后速度会变得很慢。原因可能是 V8 JavaScript 编译器似乎阻止了提前翻译。
现在最新版的 Electron(Version 11)已经支持了 M1 芯片,还需要等其他开发者更新软件。
由于 Rosetta 2 转译的程序会变成只读文件,因此自动更新将被禁止,此类程序需要用户手动更新。
程序员用 M1 MacBook 当主力开发机​是什么体验?

   虚拟机和 Windows

虽然 VMware 和 Parallels 可以在 M1 芯片的 MacBook 上使用,但是所有 Mac 虚拟化解决方案均不支持 Apple Silicon。免费开源的虚拟机 Virtualbox 更是无法运行。
现在 ARM 版 Windows 可以仿真 x86 应用程序,而微软正在研究 x64 仿真。
最近模拟器软件 CrossOver 展示了在 Mac 上运行 Windows 软件的能力,但这只是运行单个程序,而非运行虚拟机和整个系统。
而且 M1 最高只支持 16GB 内存,对虚拟机来说显得有些捉襟见肘。
程序员用 M1 MacBook 当主力开发机​是什么体验?
在运行并行测试时,Mac 开始大量在硬盘和内存之间进行数据交换,性能确实下降了。对于运行的虚拟机,这会带来更多的问题。

   结论

新款搭载 M1 芯片的 MacBook 速度快、运行安静,但是在软件方面还需要做很多工作,才能赶上搭载 Intel 芯片的 MacBook。
你可以拿它作为第二台开发电脑使用,如果作为主力开发机,可能会遇到这样那样的问题。想要更好的兼容性需要等到明年软件厂商更新,或者是 M2 发布。
另外,最高 16GB 的内存对程序员来说可能还是不够,希望未来的 Mac 有 32GB 内存可选。

参考链接:
https://news.ycombinator.com/item?id=25238608
https://steipete.com/posts/apple-silicon-m1-a-developer-perspective/
https://soffes.blog/homebrew-on-apple-silicon
https://github.com/mikelxc/Workarounds-for-ARM-mac


<section data-brushtype="text" style="padding-right: 0em;padding-left: 0em;white-space: normal;letter-spacing: 0.544px;color: rgb(62, 62, 62);font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;widows: 1;word-spacing: 2px;caret-color: rgb(255, 0, 0);text-align: center;"><strong style="color: rgb(0, 0, 0);font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.544px;"><span style="letter-spacing: 0.5px;font-size: 14px;"><strong style="font-size: 16px;letter-spacing: 0.544px;"><span style="letter-spacing: 0.5px;">—</span></strong>完<strong style="font-size: 16px;letter-spacing: 0.544px;"><span style="letter-spacing: 0.5px;font-size: 14px;"><strong style="font-size: 16px;letter-spacing: 0.544px;"><span style="letter-spacing: 0.5px;">—</span></strong></span></strong></span></strong></section><pre><pre><section style="letter-spacing: 0.544px;white-space: normal;font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;"><section powered-by="xiumi.us"><section style="margin-top: 15px;margin-bottom: 25px;opacity: 0.8;"><section><section style="letter-spacing: 0.544px;"><section powered-by="xiumi.us"><section style="margin-top: 15px;margin-bottom: 25px;opacity: 0.8;"><section><section style="margin-bottom: 15px;padding-right: 0em;padding-left: 0em;color: rgb(127, 127, 127);font-size: 12px;font-family: sans-serif;line-height: 25.5938px;letter-spacing: 3px;text-align: center;"><span style="color: rgb(0, 0, 0);"><strong><span style="font-size: 16px;font-family: 微软雅黑;caret-color: red;">为您推荐</span></strong></span></section><p style="margin: 5px 16px;padding-right: 0em;padding-left: 0em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;">一个算法工程师的日常是怎样的?</p><p style="margin: 5px 16px;padding-right: 0em;padding-left: 0em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;">深度学习框架简史:未来十年迎来黄金时期</p><section style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;"><span style="font-size: 14px;">13个算法工程师必须掌握的PyTorch Tricks</span></section><section style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;"><span style="font-size: 14px;">吴恩达上新:生成对抗网络(GAN)专项课程</span></section><section style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;text-align: center;">从SGD到NadaMax,十种优化算法原理及实现</section></section></section></section></section></section></section></section></section>

程序员用 M1 MacBook 当主力开发机​是什么体验?

本篇文章来源于: 深度学习这件小事

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写

发表评论

表情 格式 链接 私密 签到
扫一扫二维码分享