Skip to content

Compiling to macOS + Windows target not supported? #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ryanblock opened this issue Mar 24, 2023 · 8 comments
Closed

Compiling to macOS + Windows target not supported? #623

ryanblock opened this issue Mar 24, 2023 · 8 comments

Comments

@ryanblock
Copy link

ryanblock commented Mar 24, 2023

Hello! This issue follows up on #390 (👋🏼 @calavera Architect Sandbox support for Rust is finally quite close!)

So, as before, Architect Sandbox provides a full, Docker-free solution for running API Gateway + Lambda on Macs, Windows, and Linux machines. We now have Lambda Runtime API support nearly complete, and I'm working towards releasing an officially Architect + AWS Lambda Rust Runtime plugin that will seamlessly allow folks to author Rust Lambda functions, test them in Sandbox on their local machine, and deploy that code to real Lambda.

Unfortunately, it looks like right now the Rust runtime (via Cargo Lambda) only appears to support building to AWS Linux (see: here, here). Am I missing something? How can we build to the host platform and execute natively for local testing before shipping?

This does seem possible, as I pieced together cargo lambda watch + cargo lambda invoke compiles something platform native, but it doesn't appear to be obviously exposed, and I'm not sure how to verify that because (for me) watch + invoke is currently broken:

tab 1 (sudo cargo lambda watch -a 127.0.0.1 -p 9000)
sudo cargo lambda watch -a 127.0.0.1 -p 9000
Password:
 INFO invoke server listening on 127.0.0.1:9000
 INFO starting lambda function function="_" manifest="Cargo.toml"
   Compiling proc-macro2 v1.0.53
   Compiling unicode-ident v1.0.8
   Compiling quote v1.0.26
   Compiling autocfg v1.1.0
   Compiling syn v1.0.109
   Compiling serde_derive v1.0.158
   Compiling serde v1.0.158
   Compiling cfg-if v1.0.0
   Compiling pin-project-lite v0.2.9
   Compiling futures-core v0.3.27
   Compiling memchr v2.5.0
   Compiling log v0.4.17
   Compiling libc v0.2.140
   Compiling futures-channel v0.3.27
   Compiling futures-task v0.3.27
   Compiling itoa v1.0.6
   Compiling slab v0.4.8
   Compiling once_cell v1.17.1
   Compiling futures-sink v0.3.27
   Compiling futures-util v0.3.27
   Compiling pin-utils v0.1.0
   Compiling fnv v1.0.7
   Compiling futures-io v0.3.27
   Compiling tracing-core v0.1.30
   Compiling tokio v1.26.0
   Compiling num-traits v0.2.15
   Compiling httparse v1.8.0
   Compiling percent-encoding v2.2.0
   Compiling form_urlencoded v1.1.0
   Compiling num-integer v0.1.45
   Compiling serde_json v1.0.94
   Compiling tower-service v0.3.2
   Compiling ryu v1.0.13
   Compiling try-lock v0.2.4
   Compiling tinyvec_macros v0.1.1
   Compiling want v0.3.0
   Compiling tinyvec v1.6.0
   Compiling httpdate v1.0.2
   Compiling syn v2.0.9
   Compiling unicode-bidi v0.3.13
   Compiling socket2 v0.4.9
   Compiling mio v0.8.6
   Compiling num_cpus v1.15.0
   Compiling tower-layer v0.3.2
   Compiling lazy_static v1.4.0
   Compiling base64 v0.13.1
   Compiling sharded-slab v0.1.4
   Compiling unicode-normalization v0.1.22
   Compiling thread_local v1.1.7
   Compiling encoding_rs v0.8.32
   Compiling mime v0.3.17
   Compiling idna v0.3.0
   Compiling tracing-subscriber v0.3.16
   Compiling url v2.3.1
   Compiling syn v1.0.109======>        ] 83/115: serde_der...
   Compiling serde_derive v1.0.158
   Compiling tracing-subscriber v0.3.16
   Compiling serde v1.0.158
   Compiling futures-macro v0.3.27
   Compiling tokio-macros v1.8.2
   Compiling tracing-attributes v0.1.23
   Compiling pin-project-internal v1.0.12
   Compiling async-stream-impl v0.3.4
   Compiling async-stream v0.3.4
   Compiling futures-util v0.3.27
   Compiling pin-project v1.0.12
   Compiling tracing v0.1.37
   Compiling bytes v1.4.0
   Compiling serde_json v1.0.94
   Compiling chrono v0.4.24
   Compiling query_map v0.6.0
   Compiling serde_urlencoded v0.7.1
   Compiling http v0.2.9
   Compiling tokio v1.26.0
   Compiling http-body v0.4.5
   Compiling http-serde v1.1.2
   Compiling aws_lambda_events v0.7.3
   Compiling futures-executor v0.3.27
   Compiling tower v0.4.13
   Compiling futures v0.3.27
   Compiling hyper v0.14.25
   Compiling tokio-stream v0.1.12
   Compiling lambda_runtime_api_client v0.7.0
   Compiling lambda_runtime v0.7.3
   Compiling lambda_http v0.7.3
   Compiling get-rust v0.1.0 (/my/project/path/rust)
warning: unused import: `RequestExt`
 --> src/main.rs:1:58
  |
1 | ...Body, Error, Request, RequestExt, Response};
  |                          ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `get-rust` (bin "get-rust") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 7.78s
     Running `target/debug/get-rust`
ERROR Lambda runtime invoke{requestId="96066dac-26fd-4808-ae62-841745e21478" xrayTraceId="Root=1-641e257a-2f4fe7cea4bbaeb0c5558e1d;Parent=b22e5ff7aa592925;Sampled=1"}: Error("data did not match any variant of untagged enum LambdaRequest", line: 0, column: 0)
tab 2 (cargo lambda invoke --data-ascii "{ \"command\": \"hi\" }")
# tab 2
cargo lambda invoke --data-ascii "{ \"command\": \"hi\" }"
Error: serde_json::error::Error

  × data did not match any variant of untagged enum LambdaRequest

Note: invoke documentation doesn't mention watch at all.

Steps to reproduce

  • Platform: Mac (M2, Ventura)
  • Follow readme for creating boilerplate Rust function (cargo lambda new $function_name)
  • (Unclear from here how to compile to host platform)
  • Run watch + invoke → broken
@timClicks
Copy link
Contributor

This package uses cross-compilation to produce Linux-native binaries for deployment into Lambda. Under this model, there isn't really a method to support macOS and Windows executables.

@ryanblock
Copy link
Author

That isn’t strictly true though, as running watch does indeed produce a macOS binary on my local machine.

@greenwoodcm
Copy link
Contributor

if you want to compile for whatever platform you're compiling on, can't you just cargo build? i don't think you need cargo lambda at all.

@bnusunny
Copy link
Contributor

bnusunny commented Mar 26, 2023

You should be able to specify the target for cargo lambda build. Here is from the output of cargo lambda build --help.

-target <TRIPLE>                  Build for the target triple [env: CARGO_BUILD_TARGET=]

You could find the target triples in rustc doc here.

@ryanblock
Copy link
Author

@bnusunny:

$ cargo lambda build --target x86_64-apple-darwin
Password:
Error: 
  × invalid or unsupported target for AWS Lambda: x86_64-apple-darwin

$ cargo lambda build --target aarch64-apple-darwin
Error: 
  × invalid or unsupported target for AWS Lambda: aarch64-apple-darwin

@greenwoodcm: you're right, it does look like cargo build appears to work, although it's unclear to me what impact that may have on the final build output (as opposed to whatever cargo lambda build is doing).

@bnusunny
Copy link
Contributor

Oh, cargo lambda limits the targets.

cargo lambda build is equal to cargo build --release plus stripping the binary. You could use this approach.

@ryanblock
Copy link
Author

Dope, I'll consider this solved then! If you're amenable (and think it'd be worthwhile), I'd be happy to open a PR for a minor readme update.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for the maintainers of this repository to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants