Why is anyhow not working in the stable version? - rust

I have a clean project to which I include anyhow 1.0.66.
Installed the latest version of rust.
I'm getting an error saying that anyhow requires a nightly version. Perhaps this is due to the use of backtrace, but it is supported in rust version 1.65. I don't understand how to solve the problem.
Cargo.toml
[package]
name = "libfs"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = {version = "1.22", features = ["full"]}
anyhow = {version = "1.0.66", features = ["default"]}
src/lib.rs
#[tokio::test]
async fn run_test() {
println!("test");
}
output
$ cargo build
Compiling anyhow v1.0.66
error[E0554]: `#![feature]` may not be used on the stable release channel
--> /home/dima/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.66/src/lib.rs:214:32
|
214 | #![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0554]: `#![feature]` may not be used on the stable release channel
--> /home/dima/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.66/src/lib.rs:214:61
|
214 | #![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))]
| ^^^^^^^^^^^
For more information about this error, try `rustc --explain E0554`.
error: could not compile `anyhow` due to 2 previous errors

The problem was solved by:
rm -rf target
cargo check
This seems to be related to dtolnay/anyhow/issues/250 and rust-lang/rust-analyzer/issues/12973.

Related

Properly link to xfixes

I am trying to build the following program:
use x11::xfixes::XFixesHideCursor;
use x11::xlib::XDefaultRootWindow;
use x11::xlib::XOpenDisplay;
use x11::xlib::XSync;
fn main() {
let display;
let window;
unsafe {
display = XOpenDisplay(&0);
window = XDefaultRootWindow(display);
XFixesHideCursor(display, window);
XSync(display, 1);
}
}
Cargo.toml:
[package]
name = "xhidecursor"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
x11 = { version = "2.20.0", features = ["xlib"] }
Which fails with:
$ cargo run
Compiling xhidecursor v0.1.0 (/home/neumann/xhidecursor)
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" "/tmp/rustc90arZ7/symbols.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.1mqky27w09vwj4k3.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.2hnupqzwx9pp7uzf.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.2ncee6h15dx790kk.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.3wcgezgg5zbsr34g.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.4icvi7j5fuzwog4h.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.4l8ef34cbk2a0uy7.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.ropukbb1bsg3lid.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.37qtt1vkgdsjm1zb.rcgu.o" "-Wl,--as-needed" "-L" "/home/neumann/xhidecursor/target/debug/deps" "-L" "/usr/lib" "-L" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/neumann/xhidecursor/target/debug/deps/libx11-f4fa73bc30743fb8.rlib" "/home/neumann/xhidecursor/target/debug/deps/liblibc-f25e23d2977f32be.rlib" "-Wl,--start-group" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-5670385a2fe8b60b.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fd56ba6dbf7aaecc.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-b8acf8e5c2e85baa.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-1706edefffdca0a2.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-f483302e0b13708e.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-725b0718fc18e1ed.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-de685fcf2157e6fb.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-f613ac3eda05b9ff.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-3de98a7d049af6a1.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-c12183655bdce152.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-0fc7beea925de7e3.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-8c34825485bf59dc.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-ba5f7e926e729d81.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-643de0950163a839.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-539ea2f72ef89687.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-871432094bb4c885.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-ef1a8ee61f2e39bf.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-f1646747442c1c7b.rlib" "-Wl,--end-group" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-ff283b4bf550fa1c.rlib" "-Wl,-Bdynamic" "-lX11" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
= note: /usr/bin/ld: /home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.ropukbb1bsg3lid.rcgu.o: in function `xhidecursor::main':
/home/neumann/xhidecursor/src/main.rs:13: undefined reference to `XFixesHideCursor'
collect2: error: ld returned 1 exit status
= help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
error: could not compile `xhidecursor` due to previous error
I already resolved a similar linking issue by including the x11 feature xlib in my Cargo.toml. However, the x11 crate does not seem to ship a feature for xfixes.
What is the correct way to also link to xfixes?
It turned out to be a bug in the x11 crate:
https://github.com/AltF02/x11-rs/issues/158
It was fixed upstream, but no release has been made yet.

Rust-GSL Crate not linking to Rust project

I am trying to use GSL in Rust https://docs.rs/GSL/6.0.0/rgsl/ but am having trouble as I am very new to Rust. Every other crate I have tried to use just works by including the dependency in the Cargo.toml file. However, it doesn't seem to be this simple for this crate.
I have GSL installed and in Visual Studio 2022 I can successfully include it and I successfully built a program which uses functions from the library in C++.
#include <iostream>
#include <gsl/gsl_specfunc.h>
int main()
{
double k = 0.5;
double k_prime = sqrt(1 - k * k);
double K = gsl_sf_ellint_Kcomp(k, GSL_PREC_DOUBLE);
double K_prime = gsl_sf_ellint_Kcomp(k_prime, GSL_PREC_DOUBLE);
std::cout << K/K_prime << "\n";
}
I use IntelliJ as my Rust IDE, and I have a project with a Cargo.toml
[package]
name = "rust-gsl-test"
version = "0.1.0"
edition = "2021"
[dependencies]
GSL = "4.0"
In IntelliJ's terminal, when I type cargo build, I get
error: linking with `link.exe` failed: exit code: 1181
|
= note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\link.exe" "/DEF:C:\\Users\\etcto\\AppData\\Local\\Temp\\rustckB
WI9y\\lib.def" "/NOLOGO" "C:\\Users\\etcto\\AppData\\Local\\Temp\\rustckBWI9y\\symbols.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.0
.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.1.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.
gsl_sys.59103b07-cgu.10.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.11.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\g
sl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.12.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.2.rcgu.o" "D:\\GitHub\\rust-ellint\
\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.3.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.4.rcgu.o" "D:
\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.5.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.5910
3b07-cgu.6.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.7.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd76
4caa3b2be.gsl_sys.59103b07-cgu.8.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.9.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\
\deps\\gsl_sys-0d1cd764caa3b2be.3ehg95o16e12j0cb.rcgu.rmeta" "/LIBPATH:D:\\GitHub\\rust-ellint\\target\\debug\\deps" "/LIBPATH:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-w
indows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "gsl.lib" "gslcblas.lib" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\liblibc-33d50219ec2d56d1.rlib" "/LIBPATH:C:\\Users\\etct
o\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "std-fdaa63d6970be740.dll.lib" "C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-p
c-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-3f507ba7adac1c2a.rlib" "legacy_stdio_definitions.lib" "kernel32.lib" "advapi32.lib" "userenv.lib" "kerne
l32.lib" "ws2_32.lib" "bcrypt.lib" "msvcrt.lib" "legacy_stdio_definitions.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\
\x86_64-pc-windows-msvc\\lib" "/OUT:D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.dll" "/OPT:REF,NOICF" "/DLL" "/IMPLIB:D:\\GitHub\\rust-ellint\\target\\debug\
\deps\\gsl_sys-0d1cd764caa3b2be.dll.lib" "/DEBUG" "/NATVIS:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users
\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
= note: LINK : fatal error LNK1181: cannot open input file 'gsl.lib'
error: could not compile `GSL-sys` due to previous error
and when I try to run a very basic "main.rs", I get
Compiling GSL-sys v2.0.2
error: linking with `link.exe` failed: exit code: 1181
|
= note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\link.exe" "/DEF:C:\\Users\\etcto\\AppData\\Local\\Temp\\rustcFvqjHf\\lib.def" "/NOLOGO" "C:\\Users\\etcto\\AppData\\Local\\Temp\\rustcFvqjHf\\symbols.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.0.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.1.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.10.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.11.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.12.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.2.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.3.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.4.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.5.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.6.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.7.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.8.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.gsl_sys.59103b07-cgu.9.rcgu.o" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.3ehg95o16e12j0cb.rcgu.rmeta" "/LIBPATH:D:\\GitHub\\rust-ellint\\target\\debug\\deps" "/LIBPATH:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "gsl.lib" "gslcblas.lib" "D:\\GitHub\\rust-ellint\\target\\debug\\deps\\liblibc-33d50219ec2d56d1.rlib" "/LIBPATH:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "std-fdaa63d6970be740.dll.lib" "C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-3f507ba7adac1c2a.rlib" "legacy_stdio_definitions.lib" "kernel32.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "msvcrt.lib" "legacy_stdio_definitions.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.dll" "/OPT:REF,NOICF" "/DLL" "/IMPLIB:D:\\GitHub\\rust-ellint\\target\\debug\\deps\\gsl_sys-0d1cd764caa3b2be.dll.lib" "/DEBUG" "/NATVIS:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\etcto\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
= note: LINK : fatal error LNK1181: cannot open input file 'gsl.lib'
error: aborting due to previous error
error: could not compile `GSL-sys` due to 2 previous errors
Process finished with exit code 101
where main.rs is
use rgsl;
fn main() {
k = 2;
K = rgsl::pow::Pow::pow_2(&k);
println!("{K}")
}

Cannot add tuntap crate to my rust project

My Cargo.toml contains this:
[package]
name = "p2pvpn"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.5"
tuntap = "0.2.0"
When I run cargo check I've got this error:
Checking tokio-async-await v0.1.7
Checking tokio-threadpool v0.1.18
error[E0557]: feature has been removed
--> /home/tom/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-async-await-0.1.7/src/lib.rs:2:44
|
2 | #![feature(rust_2018_preview, async_await, await_macro, futures_api)]
| ^^^^^^^^^^^ feature has been removed
|
= note: subsumed by `.await` syntax
error[E0432]: unresolved import `std::await`
--> /home/tom/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-async-await-0.1.7/src/lib.rs:35:9
|
35 | pub use std::await as std_await;
| ^^^^^^^^^^^^^^^^^^^^^^^ no `await` in the root
Some errors have detailed explanations: E0432, E0557.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `tokio-async-await` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
Should I rather select different version of tuntap crate or is there some different crate for managing tun/tap devices?

Compiling Rocket in Bazel

I'm attempting to get a working prototype of the following scenario:
Language: Rust (rustc 1.45.0-nightly (ad4bc3323 2020-06-01))
Framework: Rocket v0.4.4
Build Tool: Bazel
Platform: Mac OS X / Darwin x64
Running bazel build //web-api yields the below error. I believe, based on looking at the Cargo.lock file it is because Rocket's dependency on the hyper library specifies a dependency on the log 0.3.9 library. For whatever reason it is not using the more recent log=0.4.x. That said, I don't know why it's pulling this library since, if I build it manually, it works fine.
ERROR: /private/var/tmp/_bazel_nathanielford/2a39169ea9f6eb02fe788b12f9eae88f/external/raze__log__0_3_9/BUILD.bazel:27:1: error executing shell command: '/bin/bash -c CARGO_MANIFEST_DIR=$(pwd)/external/raze__log__0_3_9 external/rust_darwin_x86_64/bin/rustc "$#" --remap-path-prefix="$(pwd)"=__bazel_redacted_pwd external/raze__log__0_3_9/src/lib.rs -...' failed (Exit 1) bash failed: error executing command /bin/bash -c 'CARGO_MANIFEST_DIR=$(pwd)/external/raze__log__0_3_9 external/rust_darwin_x86_64/bin/rustc "$#" --remap-path-prefix="$(pwd)"=__bazel_redacted_pwd' '' external/raze__log__0_3_9/src/lib.rs ... (remaining 24 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
error[E0425]: cannot find function `set_logger` in crate `log`
--> external/raze__log__0_3_9/src/lib.rs:731:16
|
731 | match log::set_logger(&ADAPTOR) {
| ^^^^^^^^^^ not found in `log`
|
help: consider importing this function
|
204 | use set_logger;
|
The following is my directory structure:
/
|-WORKSPACE
|-BUILD # Empty
|-web-api/
| |-BUILD
| |-src/
| | |-main.rs
| |-cargo/
| |-Cargo.toml
| |-Cargo.lock
| |-BUILD.bazel
| |-remote/
| |-... (Cargo-raze files)
In order to set up the cargo-raze I did the following, following instructions from the github page.:
$ cd web-api/cargo
$ cargo generate-lockfile
$ cargo vendor --versioned-dirs --locked
$ cargo raze
(The generate-lockfile is what creates the Cargo.lock file, and the cargo raze is what creates the BUILD.bazel file and all the contents of the remote sub directory.)
And then to execute the bazel build I go back to the root and run bazel build //web-api, which produces the above error.
This is my WORKSPACE file:
workspace(name = "rocket-bazel")
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_rust",
sha256 = "f21c67fc2fef9d57fa3c81fde1defd9e57d451883388c0a469ec1c470fd30dcb",
strip_prefix = "rules_rust-master",
urls = [
"https://github.com/bazelbuild/rules_rust/archive/master.tar.gz"
],
)
http_archive(
name = "bazel_skylib",
sha256 = "9a737999532daca978a158f94e77e9af6a6a169709c0cee274f0a4c3359519bd",
strip_prefix = "bazel-skylib-1.0.0",
url = "https://github.com/bazelbuild/bazel-skylib/archive/1.0.0.tar.gz",
)
load("#io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")
rust_repositories(version="nightly", iso_date="2020-06-02")
load("#io_bazel_rules_rust//:workspace.bzl", "bazel_version")
bazel_version(name = "bazel_version")
load("//web-api/cargo:crates.bzl", "raze_fetch_remote_crates")
raze_fetch_remote_crates()
This is my web-api/BUILD file:
load("#io_bazel_rules_rust//rust:rust.bzl", "rust_binary")
rust_binary(
name = "web-api",
srcs = ["src/main.rs"],
deps = [
"//web-api/cargo:rocket",
],
)
And my web-api/cargo/Cargo.toml file:
load("#io_bazel_rules_rust//rust:rust.bzl", "rust_binary")
rust_binary(
name = "web-api",
srcs = ["src/main.rs"],
deps = [
"//web-api/cargo:rocket",
],
)
I've run out of ideas as to what to try. I can get this to compile without Bazel, just using rust (though obviously the files are in slightly different places). I can get it to compile inside a Docker container. I just can't get Bazel (necessarily with cargo raze, either in vendor or remote mode) to run successfully: I assume that there is some mismatch in compile target or the nightly build that is not being properly set - but I'm not sure how to diagnose or get past that.
Here is a link to a repository with the files/structure I tried.
I had a similar issue when I made a minimal Bazel workspace with rust and the log crate together with env_logger crate. I found a similar issue when you try to compile without features = ["std"]. I then tried to enable that in Cargo.toml on the log dependency without success.
My solution is that in Cargo.toml under [raze] I added:
default_gen_buildrs = true
I could trace it down to that when default_gen_buildrs flag is not set in the generated log crate the BUILD.bazel file did not have a cargo_build_script definition or this:
crate_features = [
"std",
],

Unable to compile Actix on macOS Mojave due to "ar crs" "malformed object (unknown load command 1)"

I'm unable to compile a basic example using Actix. I suspect I might be missing some libraries but I have no clue of what it could be. I also upgraded to Mojave a few days ago, but I'm not sure if this is related.
It seems to complain about ar crs and about an internal error happening in ranlib when running this command.
main.rs:
extern crate actix_web;
use actix_web::{server, App, HttpRequest};
fn index(_req: &HttpRequest) -> &'static str {
"Hello world!"
}
fn main() {
server::new(|| App::new().resource("/", |r| r.f(index)))
.bind("127.0.0.1:8088")
.unwrap()
.run();
}
Cargo.toml:
actix-web = "0.7.8"
Backtrace I obtain:
mbp-de-matthieu:hello-world matthieu$ RUST_BACKTRACE=1 cargo build
Compiling backtrace-sys v0.1.24
Compiling miniz-sys v0.1.10
Compiling brotli-sys v0.3.2
Compiling ring v0.13.2
Compiling tokio-current-thread v0.1.3
error: failed to run custom build command for `miniz-sys v0.1.10`
process didn't exit successfully: `/Users/matthieu/Documents/Rust/actix/hello-world/target/debug/build/miniz-sys-dc81523acb01e9e7/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-apple-darwin = None
CC_x86_64_apple_darwin = None
HOST_CC = None
CC = None
CFLAGS_x86_64-apple-darwin = None
CFLAGS_x86_64_apple_darwin = None
HOST_CFLAGS = None
CFLAGS = None
DEBUG = Some("true")
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-o" "/Users/matthieu/Documents/Rust/actix/hello-world/target/debug/build/miniz-sys-d59b36acd5b3db67/out/miniz.o" "-c" "miniz.c"
exit code: 0
AR_x86_64-apple-darwin = None
AR_x86_64_apple_darwin = None
HOST_AR = None
AR = None
running: "ar" "crs" "/Users/matthieu/Documents/Rust/actix/hello-world/target/debug/build/miniz-sys-d59b36acd5b3db67/out/libminiz.a" "/Users/matthieu/Documents/Rust/actix/hello-world/target/debug/build/miniz-sys-d59b36acd5b3db67/out/miniz.o"
cargo:warning=/usr/local/Cellar/cctools/855/bin/ranlib: object: /Users/matthieu/Documents/Rust/actix/hello-world/target/debug/build/miniz-sys-d59b36acd5b3db67/out/libminiz.a(miniz.o) malformed object (unknown load command 1)
cargo:warning=ar: internal ranlib command failed
exit code: 1
--- stderr
thread 'main' panicked at '
Internal error occurred: Command "ar" "crs" "/Users/matthieu/Documents/Rust/actix/hello-world/target/debug/build/miniz-sys-d59b36acd5b3db67/out/libminiz.a" "/Users/matthieu/Documents/Rust/actix/hello-world/target/debug/build/miniz-sys-d59b36acd5b3db67/out/miniz.o" with args "ar" did not execute successfully (status code exit code: 1).
The complete backtrace is too large to include on Stack Overflow.
It seems to work after installing cctools through MacPorts.
For some reason, installing it through brew didn't seem to work.
I had the same error.
When I replaced cctools 855 with 921 from this tap then cargo build worked: https://github.com/dgsga/homebrew-cctools
brew unlink cctools
brew tap dgsga/cctools
brew install dgsga/cctools/mtoc
Mojave 10.14.3, Rust 1.33.0, actix-web 0.7.18

Resources