sexta-feira, 21 de março de 2025

Solution to failed to acquire username/password from local configuration on rust git libs

Let's say you need to work on a Rust project that depends on other libraries hosted in a private Git repository. This project uses the repository's HTTPS URL. For example:



your-lib = { git = "ssh://git@github.com/your-company/your-lib.git"}

Then you try to start the project and encounter the following error:


$ cargo run

    Blocking waiting for file lock on package cache

    Updating crates.io index

    Updating git repository `https://github.com/your-company/your-lib.git`

error: failed to get `outbox-pattern-processor` as a dependency of package `anti-fraud-service v0.1.0 (/project/your-project)`

Caused by:

  failed to load source for dependency `your-lib`

Caused by:

  Unable to update https://github.com/your-company/your-lib.git?tag=v1.0.0#49efa247

Caused by:

  failed to fetch into: /home/tiago.motta/.cargo/git/db/your-lib-31d59910066df49a

Caused by:

  revision 49efa2476e2613cf809315b4b0abf16f079b5dcb not found

Caused by:

  failed to authenticate when downloading repository

  * attempted to find username/password via git's `credential.helper` support, but failed

  if the git CLI succeeds then `net.git-fetch-with-cli` may help here

  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:

  failed to acquire username/password from local configuration


The solution is simple. Just edit your global .gitconfig to replace HTTPS URLs with SSH by adding the following lines:


[url "ssh://git@github.com/"]

insteadOf = https://github.com/




segunda-feira, 10 de março de 2025

What is the best rust lib to post custom metric on datadog?

The best library for recording custom metrics in Datadog using Rust is dogstatsd (https://crates.io/crates/dogstatsd).

The alternative statsd (https://crates.io/crates/statsd) does not allow sending tags. There is even a fork, datadog-statsd (https://crates.io/crates/datadog-statsd), that enables tag sending. However, both define the client without deriving Clone, which prevents using this client as with_state in Axum, resulting in an error similar to this:


the trait bound `...` is not satisfied

the trait `Clone` is not implemented for `...`rustcClick for full compiler diagnostic

method_routing.rs(168, 16): required by a bound in `post`

....rs(6, 1): consider annotating `...` with `#[derive(Clone)]`: `#[derive(Clone)]

`

the trait bound `...` is not satisfied

the trait `Clone` is not implemented for `...`rustcClick for full compiler diagnostic

method_routing.rs(168, 16): required by a bound in `post`

....rs(6, 1): consider annotating `...` with `#[derive(Clone)]`: `#[derive(Clone)]

`

the trait bound `fn(axum::extract::State<...>, Json<...>) -> impl futures::Future<Output = Result<hyper::Response<axum::body::Body>, AppError>> {...::handler}: Handler<_, _>` is not satisfied


the following other types implement trait `Handler<T, S>`:

  `Layered<L, H, T, S>` implements `Handler<T, S>`

  `MethodRouter<S>` implements `Handler<(), S>`rustcClick for full compiler diagnostic

....rs(55, 32): required by a bound introduced by this call

method_routing.rs(166, 16): required by a bound in `post`

the trait bound `fn(axum::extract::State<...>, axum::Json<...>) -> impl futures::Future<Output = Result<hyper::Response<axum::body::Body>, ...>> {...}: Handler<_, _>` is not satisfied


the following other types implement trait `Handler<T, S>`:

  `Layered<L, H, T, S>` implements `Handler<T, S>`

  `MethodRouter<S>` implements `Handler<(), S>`rustcClick for full compiler diagnostic

....rs(55, 32): required by a bound introduced by this call

method_routing.rs(166, 16): required by a bound in `post`

axum::routing::method_routing

pub fn post<H, T, S>(handler: H) -> MethodRouter<S, Infallible>

where

    H: Handler<T, S>,

    T: 'static,

    S: Clone + Send + Sync + 'static,

H = fn handler(State<...>, …) -> …, S = ...




 

terça-feira, 18 de fevereiro de 2025

Solution to failed to run custom build command for `openssl-sys v0.9.104`

 When upgrading "reqwests" library I got the following error on docker build:

#18 182.8 The following warnings were emitted during compilation:

#18 182.8 

#18 182.8 warning: openssl-sys@0.9.104: Could not find directory of OpenSSL installation, and this `-sys` crate cannot proceed without this knowledge. If OpenSSL is installed and this crate had trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the compilation process. See stderr section below for further information.

#18 182.8 

#18 182.8 error: failed to run custom build command for `openssl-sys v0.9.104`

#18 182.8 

#18 182.8 Caused by:

#18 182.8   process didn't exit successfully: `/usr/app/target/release/build/openssl-sys-ff7852766e78b685/build-script-main` (exit status: 101)

#18 182.8   --- stdout

#18 182.8   cargo:rustc-check-cfg=cfg(osslconf...

 

Could not find the solution after googling, but I tried the obvious solution, install openssl-dev into the docker image:

FROM rust:1.82-alpine AS builder

RUN apk add --no-cache openssl-dev


After this I got the following error:

x86_64-alpine-linux-musl/bin/ld: cannot find -lssl: No such file or directory

x86_64-alpine-linux-musl/bin/ld: cannot find -lcrypto: No such file or directory


And the fix for this was adding the openssl-libs-static:

FROM rust:1.82-alpine AS builder

RUN apk add --no-cache openssl-dev openssl-libs-static

 

Fixed


sexta-feira, 3 de janeiro de 2025

Solution to cargo-tarpaulin and missing `GLIBC_2.38' not found

Using cargo-tarpaulin 0.31.4 using binstall on Ubuntu 22.04 may result in errors like the following:

cargo-tarpaulin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.38' not found (required by cargo-tarpaulin)

cargo-tarpaulin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.39' not found (required by cargo-tarpaulin)

I resolved the issue by avoiding binstall. Instead of running: 

I resolved the issue by avoiding binstall. Instead of running

> cargo binstall cargo-tarpaulin

I used the following command:

> cargo insatall cargo-tarpaulin

While this installation method is significantly slower, it successfully resolves the issue.

I suspect similar problems could arise with other Rust libraries when using binstall.