跳转至

MacOS 开发环境

安装 os 依赖

# for furnace-connect
brew install pkgconf # pkg-config
brew install llvm 
brew install lld

# for furnace
brew install zlib ncurses
  • 注意设置 llvm 环境变量:
fish_add_path /opt/homebrew/opt/llvm/bin


set -gx LDFLAGS "-L/opt/homebrew/opt/llvm/lib"
set -gx CPPFLAGS "-I/opt/homebrew/opt/llvm/include"


# 查看环境变量:
echo $LDFLAGS  
echo $CPPFLAGS

安装 magic & mojo

  • 安装 magic
task magic:install

安装 rustup & rust

  • 使用 rustup 安装 rust

vscode 配置

  • 安装 mojo 插件

FAQ:

macos 编译 rust ffi 问题

  • 遇到的链接错误
0  0x100526074  __assert_rtn + 72
1  0x100493994  ld::DynamicAtomFile::makeNamedAtom(std::__1::basic_string_view<char, std::__1::char_traits<char>>, ld::file_format::Scope, bool) + 488
2  0x10045c640  ld::InputFiles::ObjectFileParser::addAtomsForSection(mach_o::Image const&, ld::InputFiles::ObjectFileParser::SectionData&) + 5528
3  0x10045e058  ld::InputFiles::SliceParser::parseObjectFile(mach_o::Header const*) const + 2904
4  0x10046f830  ld::InputFiles::parseAllFiles(void (ld::AtomFile const*) block_pointer)::$_8::operator()(unsigned long, ld::FileInfo const&) const + 440
5  0x190e59428  _dispatch_client_callout2 + 20
6  0x190e6d850  _dispatch_apply_invoke3 + 336
7  0x190e593e8  _dispatch_client_callout + 20
8  0x190e5ac68  _dispatch_once_callout + 32
9  0x190e6c8a4  _dispatch_apply_invoke + 252
10  0x190e593e8  _dispatch_client_callout + 20
11  0x190e6b080  _dispatch_root_queue_drain + 864
12  0x190e6b6b8  _dispatch_worker_thread2 + 156
13  0x191005fd0  _pthread_wqthread + 228
ld: Assertion failed: (name.size() <= maxLength), function makeSymbolStringInPlace, file SymbolString.cpp, line 74.
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mojo: error: failed to link executable
Command executed successfully
  • 可能的修改方法 .cargo/config.toml: (和 lld 有关)
#
# brew install llvm
# brew install lld
#
[target.aarch64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=lld", ]
#rustflags = ["-C", "link-arg=-fuse-ld=/opt/homebrew/opt/lld/bin/ld64.lld"]

参考:

  • https://users.rust-lang.org/t/linker-dies-when-using-knuffel/101753/7
  • https://github.com/rust-lang/rust/issues/130729#issuecomment-2645935599