rust icon indicating copy to clipboard operation
rust copied to clipboard

`No such file or directory, Cargo.toml.backup`

Open pheuter opened this issue 3 years ago • 10 comments

Running > npx vercel dev and navigating to http://localhost:3000/api/user throws the following error:

> Building [email protected]:api/user.rs
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
...more warnings
error: build failed
failed to `cargo build`
[Error: ENOENT: no such file or directory, stat './my-rust-app/api/Cargo.toml.backup'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: './my-rust-app/api/Cargo.toml.backup'
}

api/user.rs:

use http::StatusCode;
use std::error::Error;
use vercel_lambda::{error::VercelError, lambda, IntoResponse, Request, Response};

fn handler(_: Request) -> Result<impl IntoResponse, VercelError> {
    let response = Response::builder()
        .status(StatusCode::OK)
        .header("Content-Type", "text/plain")
        .body("Hello World")
        .expect("Internal Server Error");

    Ok(response)
}

// Start the runtime with the handler
fn main() -> Result<(), Box<dyn Error>> {
    Ok(lambda!(handler))
}

api/Cargo.toml:

[package]
name = "index"
version = "1.0.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"

[dependencies]
http = "0.1"
vercel_lambda = "*"

[[bin]]
name = "user"
path = "user.rs"

vercel.json:

{
  "functions": {
    "api/**/*.rs": {
      "runtime": "[email protected]"
    }
  }
}

pheuter avatar Sep 09 '21 13:09 pheuter

Thank you for reporting! Are you interested in contributing here to try and address this? 🙏

leerob avatar Sep 09 '21 13:09 leerob

Hi,

@pheuter what OS are you running this on? What's your cargo --version and rustc --version?

icyJoseph avatar Sep 09 '21 14:09 icyJoseph

> cargo --version
cargo 1.54.0 (5ae8d74b3 2021-06-22)

> rustc --version
rustc 1.54.0 (a178d0322 2021-07-26)

> rustup show
Default host: aarch64-apple-darwin
rustup home:  /Users/mark/.rustup

stable-aarch64-apple-darwin (default)
rustc 1.54.0 (a178d0322 2021-07-26)

@leerob I wouldn't mind at all if I can find some time outside of my day job, might be tough right now. I'm also fairly new to Rust and have never worked with Vercel runtimes before directly so would be some learning curve as well. Not that I'm against learning, seems like an interesting project, but time is a concern at the moment.

pheuter avatar Sep 09 '21 15:09 pheuter

Ah, I do not have a macbook at hand, but I'd just ask for one last thing, if you cd into api, and run both cargo run and cargo build, what output are you getting? If it's super long, please do try to paste any major errors you see. The cargo logs are usually very helpful at showing what has gone wrong.

I suspect that the build command used for vercel_lambda is not taking into account your architecture, but maybe we see more in the logs.

For completeness, this is what I get:

 ➜ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.43s
     Running `target/debug/user`
thread 'main' panicked at 'Could not find runtime API env var: environment variable not found', /home/joseph/.cargo/registry/src/github.com-1ecc6299db9ec823/lambda_runtime_core-0.1.2/src/runtime.rs:79:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected failure as in cargo run mode I did not set the environment, and

❯ cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s

icyJoseph avatar Sep 09 '21 16:09 icyJoseph

@icyJoseph

my-rust-app/api [main] » cargo run 
   Compiling index v1.0.0 (/Users/mark/src/pheuter/my-rust-app/api)
    Finished dev [unoptimized + debuginfo] target(s) in 2.63s
     Running `target/debug/user`
thread 'main' panicked at 'Could not find runtime API env var: environment variable not found', /Users/mark/.cargo/registry/src/github.com-1ecc6299db9ec823/lambda_runtime_core-0.1.2/src/runtime.rs:79:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
mark ~/src/pheuter/my-rust-app/api [main] » cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s

pheuter avatar Sep 09 '21 20:09 pheuter

@pheuter Alright, when you have time could you install musl-cross, as described here: https://github.com/awslabs/aws-lambda-rust-runtime#aws-cli ?

It'd seem that because this is made to run in AWS linux based environments, at runtime vercel compiles your code for linux, but your system has no cross OS linkers.

If this works, then it should definitely be on the docs page.

icyJoseph avatar Sep 10 '21 07:09 icyJoseph

@icyJoseph

I have run through the following commands, but still get the same error:

$ brew install filosottile/musl-cross/musl-cross
$ mkdir .cargo
$ echo $'[target.x86_64-unknown-linux-musl]\nlinker = "x86_64-linux-musl-gcc"' > .cargo/config

pheuter avatar Sep 10 '21 13:09 pheuter

Hi @pheuter,

I've tried to debug this, but without access to a Macbook I am not getting anywhere.

It must be that the rust compiler just doesn't understand the RUSTFLAGS used. Obviously from your first message, the problem is ivy bridge as a processor. I tried googling toolchains/linkers to help with that issue, but my google fu didn't yield anything useful.

One thing you could do to triage this is, to setup local development and make it verbose.

  1. Clone this repo, and yarn to install dependencies.
  2. Go to src/index.ts and find the variable: const builderDebug = process.env.VERCEL_BUILDER_DEBUG ? true : false; , and force that to true. The quickest way would be to just do ? true : true
  3. Run yarn tsc
  4. In your users project, change the vercel.json file to look like this:
{
	"builds": [
		{
			"src": "/api/*.rs",
			"use": "~/<path>/<to-the-cloned>/<vercel-rust-repo>/"
		}
	]
}

  1. Now, run vercel dev or which ever command you are running. The logs should be plentiful.
  2. Optionally, in src/index.ts of this repo, you could tweak the codegenFlags target-cpu by setting it to "native".

Hopefully you can get to the bottom of this.

icyJoseph avatar Sep 13 '21 08:09 icyJoseph

I am running across this same issue on my M1 machine. I tried following your instructions above but using pnpm as I don't have yarn installed and I was running into a heap of Typescript errors when running pnpm tsc. I proceeded to @ts-ignore them all and then I received the same error as in the original error (as shown in the hidden output below). However, removing all of the codegenFlags allow the function to build correctly. Eg.

const codegenFlags: string[] = [
  // '-C',
  // 'target-cpu=ivybridge',
  // '-C',
  // 'target-feature=-aes,-avx,+fxsr,-popcnt,+sse,+sse2,-sse3,-sse4.1,-sse4.2,-ssse3,-xsave,-xsaveopt'
];
Original Error: Click to expand!
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'-popcnt' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'-popcnt' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'-popcnt' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'-popcnt' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'-popcnt' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'-popcnt' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'-popcnt' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'-popcnt' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'ivybridge' is not a recognized processor for this target (ignoring processor)
'-avx' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'-popcnt' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'-sse3' is not a recognized feature for this target (ignoring feature)
'-sse4.1' is not a recognized feature for this target (ignoring feature)
'-sse4.2' is not a recognized feature for this target (ignoring feature)
'-ssse3' is not a recognized feature for this target (ignoring feature)
'-xsave' is not a recognized feature for this target (ignoring feature)
'-xsaveopt' is not a recognized feature for this target (ignoring feature)
'ivybridge' is not a recognized processor for this target (ignoring processor)
failed to `cargo build`
[Error: ENOENT: no such file or directory, lstat '/Users/oscar/Desktop/rust-on-vercel/api/Cargo.toml.backup'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: '/Users/oscar/Desktop/rust-on-vercel/api/Cargo.toml.backup'
}

Why do the codegenFlags exist in the first place given they are doing nothing here? I am oscartbeaumont#0004 on Discord if you want any help debugging/fixing this issue feel free to message me. I would be down to do a PR too.

oscartbeaumont avatar Jul 18 '22 13:07 oscartbeaumont

Hello, I have same error on Ubuntu 22.04 I commented out util lib from toml file and sample code seems to start working:

[package]
name = "index"
version = "1.0.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"

[dependencies]
http = "0.1"
vercel_lambda = "*"

# [lib]
# name = "util"
# path = "_util.rs"

YuriGor avatar Jul 24 '22 12:07 YuriGor