shuttle-hq / shuttle

Build & ship backends without writing any infrastructure files.
https://shuttle.rs
Apache License 2.0
6.09k stars 252 forks source link

Allow specifying rust toolchain/version #1125

Closed Proxxa closed 2 weeks ago

Proxxa commented 1 year ago

What happened?

In deployment, Shuttle fails to build my project because I rely on unstable features for a proc_macro that I use. In particular, I use proc_macro_span and proc_macro_internals to get the path to the calling macro. This is because I want this macro to act like include_str! and prepend the file contents with a timestamp stating when the file was created.

Here is the rust file:

// macros/src/lib.rs
#![feature(proc_macro_span, proc_macro_internals)]

extern crate proc_macro;
use std::{fs::File, path::PathBuf};

use proc_macro::{TokenStream, Span};

#[proc_macro]
pub fn file_with_date(item: TokenStream) -> TokenStream {

    // Turn input into PathBuf
    let path_string = item.to_string();
    let in_path = PathBuf::from(path_string.trim_matches('"'));

    let path = if in_path.is_absolute() {
        // Get parent directory of calling file
        let span = Span::call_site();
        let src = span.source_file();
        let invoc_path = src.path();

        // Into a PathBuf
        let mut path = PathBuf::from(PathBuf::from(invoc_path).parent().unwrap());

        // Extend
        path.extend(in_path.iter());
        path

    } else { in_path };

    // Get the file
    let file = File::open(path.clone()).expect("Failed to open file");

    // Get file metadata
    let metadata = file.metadata().expect("Failed to get file metadata");

    // Get file created time
    let created_time = metadata.created().expect("Failed to get creation time of file");

    // Turn that into a lovely timestamp
    let time_string = chrono::DateTime::<chrono::Utc>::from(created_time).to_string();

    // Output code!
    format!(r#"concat!("Last Updated {time_string}\n\n", include_str!({}))"#, path_string).parse().unwrap()
}

Here is the Cargo.toml of this proc_macro library:

# macros/Cargo.toml
[package]
name = "util_macros"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
proc-macro = true

[dependencies]
chrono = "0.4.26"

And here is the Cargo.toml of the main project:

# Cargo.toml (main directory)
[package]
name = "proxxa-somebot"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
anyhow = "1.0.68"
poise = "0.5.2"
shuttle-poise = "0.22.0"
shuttle-runtime = "0.22.0"
shuttle-secrets = "0.22.0"
tracing = "0.1.37"
tokio = "1.26.0"
rand = "0.8.5"
shuttle-rocket = "0.22.0"
rocket = "=0.5.0-rc.3"
chrono = "0.4.26"
util_macros = { path = "macros" }

BOTH directories have a rust-toolchain.toml containing the following:

# Both rust-toolchain.toml (main directory) AND macros/rust-toolchain.toml
[toolchain]
channel = "nightly"

Version

v0.22.0

Which operating system(s) are you seeing the problem on?

In deployment

Which CPU architectures are you seeing the problem on?

In deployment

Relevant log output

getting a build slot
calling gateway
connecting to 10.99.0.14:8001
connected to 10.99.0.14:8001
pooling idle connection for ("http", gateway:8001)
Load response

   Compiling util_macros v0.1.0 (/opt/shuttle/shuttle-builds/proxxa-somebot/macros)
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> macros/src/lib.rs:1:12
  |
1 | #![feature(proc_macro_span, proc_macro_internals)]
  |            ^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> macros/src/lib.rs:1:29
  |
1 | #![feature(proc_macro_span, proc_macro_internals)]

  |                             ^^^^^^^^^^^^^^^^^^^^
service build encountered an error

For more information about this error, try `rustc --explain E0554`.
error: could not compile `util_macros` (lib) due to 2 previous errors

Duplicate declaration

Proxxa commented 1 year ago

If this is not a bug and is instead a limitation enforced by Shuttle, I apologize. It is written nowhere that the nightly channel is not supported, but this is something that I'd like to do for the sake of getting information at compile time rather than runtime.

oddgrd commented 1 year ago

Hey @Proxxa! This is currently a limitation enforced by Shuttle, all users services run and build on the same container image which is pinned to 1.70 (usually the latest stable). We are working on a new service for building users services, where each one will get its own image. For this builder, we plan to allow the user to set some config for which Rust version they'd like to use, as well as native dependencies etc.

You are right that this current version cap is not mentioned anywhere, that should definitely be resolved, I'll add it to the FAQ in the docs for starters!

Proxxa commented 1 year ago

Hi @oddgrd ! Thanks for the quick response! While it's sad, this does make me look forward to future updates to shuttle. Should I close this issue, or should I keep it open as a way to track nightly support/adding this to the FAQ?

oddgrd commented 1 year ago

I think we can change this to a feature request, something like "allow specifying rust toolchain/version", and leave it open.

Proxxa commented 1 year ago

Changed the title. Unfortunately, I don't believe I can edit the label myself. Supposedly, that requires triage repo access.

oddgrd commented 1 year ago

Thanks!

jonaro00 commented 2 weeks ago

Prebuild hook script (experimental feature) can now be used to install a custom toolchain on shuttle.dev: https://docs.shuttle.dev/docs/builds#experimental-hook-scripts