Unverified 提交 cbde9032 authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi 提交者: GitHub

Rust support on macOS (#567)

上级 3193c767
...@@ -7,13 +7,17 @@ env: ...@@ -7,13 +7,17 @@ env:
jobs: jobs:
ci: ci:
runs-on: ubuntu-20.04
strategy: strategy:
matrix: matrix:
os:
- ubuntu-20.04
- macos-10.15
rust: rust:
- stable - stable
# - nightly # - nightly
runs-on: ${{ matrix.os }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
...@@ -37,7 +41,7 @@ jobs: ...@@ -37,7 +41,7 @@ jobs:
~/.cargo/registry ~/.cargo/registry
~/.cargo/git ~/.cargo/git
target target
key: ${{ runner.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.toml') }} key: ${{ matrix.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.toml') }}
- name: cargo fmt - name: cargo fmt
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
......
...@@ -36,10 +36,7 @@ fn pipe() -> [c_int; 2] { ...@@ -36,10 +36,7 @@ fn pipe() -> [c_int; 2] {
let mut fds = mem::MaybeUninit::<[c_int; 2]>::uninit(); let mut fds = mem::MaybeUninit::<[c_int; 2]>::uninit();
if libc::pipe(fds.as_mut_ptr().cast::<c_int>()) != 0 { if libc::pipe(fds.as_mut_ptr().cast::<c_int>()) != 0 {
panic!( panic!("libc::pipe() failed: {:?}", std::io::Error::last_os_error());
"libc::pipe() failed with code {}",
*libc::__errno_location()
);
} }
fds.assume_init() fds.assume_init()
......
...@@ -7,10 +7,17 @@ fn main() { ...@@ -7,10 +7,17 @@ fn main() {
return; return;
} }
let current_dir = std::env::current_dir()
.unwrap()
.into_os_string()
.into_string()
.unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
// Add C++ std lib // Add C++ std lib
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
let path = Command::new(env::var("c++").unwrap_or_else(|_| "c++".to_string())) let path = Command::new(env::var("CXX").unwrap_or_else(|_| "c++".to_string()))
.arg("--print-file-name=libstdc++.a") .arg("--print-file-name=libstdc++.a")
.output() .output()
.expect("Failed to start") .expect("Failed to start")
...@@ -31,7 +38,7 @@ fn main() { ...@@ -31,7 +38,7 @@ fn main() {
target_os = "netbsd" target_os = "netbsd"
))] ))]
{ {
let path = Command::new(env::var("c++").unwrap_or_else(|_| "c++".to_string())) let path = Command::new(env::var("CXX").unwrap_or_else(|_| "c++".to_string()))
.arg("--print-file-name=libc++.a") .arg("--print-file-name=libc++.a")
.output() .output()
.expect("Failed to start") .expect("Failed to start")
...@@ -47,8 +54,56 @@ fn main() { ...@@ -47,8 +54,56 @@ fn main() {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
{ {
panic!("Building on macOS is not currently supported"); let clang_llvm_version = "clang+llvm-12.0.0-x86_64-apple-darwin";
// TODO: The issue here is `libc++.a` that is not shipped with macOS's `c++` it seems let status = Command::new("curl")
.args(&[
"-L",
"-s",
"-O",
&format!("https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/{}.tar.xz", clang_llvm_version),
])
.current_dir(&out_dir)
.status()
.expect("Failed to start");
if !status.success() {
panic!("Failed to download libc++");
}
let status = Command::new("tar")
.args(&[
"-xf",
&format!("{}.tar.xz", clang_llvm_version),
&format!("{}/lib/libc++.a", clang_llvm_version),
&format!("{}/lib/libc++abi.a", clang_llvm_version),
])
.current_dir(&out_dir)
.status()
.expect("Failed to start");
if !status.success() {
panic!("Failed to download libc++");
}
for file in &["libc++.a", "libc++abi.a"] {
std::fs::copy(
format!("{}/{}/lib/{}", out_dir, clang_llvm_version, file),
format!("{}/{}", out_dir, file),
)
.unwrap_or_else(|_| {
panic!(
"Failed to copy static library from {}/{}/lib/{} to {}/{}",
out_dir, clang_llvm_version, file, out_dir, file
)
});
}
std::fs::remove_file(format!("{}/{}.tar.xz", out_dir, clang_llvm_version))
.expect("Failed to remove downloaded clang+llvm archive");
std::fs::remove_dir_all(format!("{}/{}", out_dir, clang_llvm_version))
.expect("Failed to remove extracted clang+llvm files");
println!("cargo:rustc-link-lib=static=c++");
println!("cargo:rustc-link-lib=static=c++abi");
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
...@@ -56,13 +111,6 @@ fn main() { ...@@ -56,13 +111,6 @@ fn main() {
// TODO: Didn't bother, feel free to PR // TODO: Didn't bother, feel free to PR
} }
let current_dir = std::env::current_dir()
.unwrap()
.into_os_string()
.into_string()
.unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
// The build here is a bit awkward since we can't just specify custom target directory as // The build here is a bit awkward since we can't just specify custom target directory as
// openssl will fail to build with `make[1]: /bin/sh: Argument list too long` due to large // openssl will fail to build with `make[1]: /bin/sh: Argument list too long` due to large
// number of files. So instead we build in place, copy files to out directory and then clean // number of files. So instead we build in place, copy files to out directory and then clean
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论