Skip to content
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

Example dependencies don't seem to be working #144

Closed
andar1an opened this issue Nov 2, 2024 · 1 comment
Closed

Example dependencies don't seem to be working #144

andar1an opened this issue Nov 2, 2024 · 1 comment

Comments

@andar1an
Copy link

andar1an commented Nov 2, 2024

I am trying to get an example script working with dependencies from the example repo, but for either dependency inclusion method, it seems that dependencies are not being compiled and cargo toml and lock may not be generated? I need to path explicit flag still to see what is happening.

For example:

//! This is a regular crate doc comment, but it also contains a partial
//! Cargo manifest.  Note the use of a *fenced* code block, and the
//! `cargo` "language".
//!
//! ```cargo
//! [dependencies]
//! time = "0.1.25"
//! ```

fn main() {
    println!("{}", time::now().rfc822z());
}

will state use of undeclared crate or module "time".

I have tried with various quotes e.g. /// vs //! vs // vs no quotes with just fence, as well as use statements and other methods of including dependency, and making sure file is executable but can't seem to get this working.

Am I missing something?

Log:

[2024-11-02T22:18:48Z INFO  rust_script] Arguments: Args { script: Some("example.ers"), script_args: ["--clear-cache"], expr: false, loop_: false, count: false, base_path: None, pkg_path: None, gen_pkg_only: false, cargo_output: true, clear_cache: false, debug: false, dep: [], extern_: [], force: false, unstable_features: [], build_kind: Normal, toolchain_version: None, wrapper: None }
[2024-11-02T22:18:48Z INFO  rust_script] input: File("example", "/home/username/example.ers", "#!/usr/bin/env rust-script\n\n// https://rust-script.org/#scripts\n// https://github.com/fornwall/rust-script/tree/main/examples\n\n//! This is a regular crate doc comment, but it also contains a partial\n//! Cargo manifest.  Note the use of a *fenced* code block, and the\n//! `cargo` \"language\".\n//!\n//! ```cargo\n//! [dependencies]\n//! time = \"0.1/home/username")
[2024-11-02T22:18:48Z INFO  rust_script] prelude_items: []
[2024-11-02T22:18:48Z INFO  rust_script] id: "757b44cade3c09a2f7355d82"
[2024-11-02T22:18:48Z INFO  rust_script] pkg_path: "/home/username/.cache/rust-script/projects/757b44cade3c09a2f7355d82"
[2024-11-02T22:18:48Z INFO  rust_script] using_cache: true
[2024-11-02T22:18:48Z INFO  rust_script::manifest] part_mani: {}
[2024-11-02T22:18:48Z INFO  rust_script::manifest] source: None
[2024-11-02T22:18:48Z INFO  rust_script::manifest] manifest: [[bin]]
    name = "example_757b44cade3c09a2f7355d82"
    path = "/home/username/example.ers"
    
    [dependencies]
    
    [package]
    authors = ["Anonymous"]
    edition = "2021"
    name = "example_757b44cade3c09a2f7355d82"
    version = "0.1.0"
    
    [profile.release]
    strip = true
    
[2024-11-02T22:18:48Z INFO  rust_script] action: InputAction { cargo_output: true, force_compile: false, execute: true, pkg_path: "/home/username/.cache/rust-script/projects/757b44cade3c09a2f7355d82", script_path: "/home/username/example.ers", using_cache: true, toolchain_version: None, debug: false, manifest: "[[bin]]\nname = \"example_757b44cade3c09a2f7355d82\"\npath = \"//home/username/example.ers\"\n\n[dependencies]\n\n[package]\nauthors = [\"Anonymous\"]\nedition = \"2021\"\nname = \"example_757b44cade3c09a2f7355d82\"\nversion = \"0.1.0\"\n\n[profile.release]\nstrip = true\n", script: None, build_kind: Normal, bin_name: "example_757b44cade3c09a2f7355d82", original_script_path: Some("example.ers") }
[2024-11-02T22:18:48Z INFO  rust_script] creating pkg dir...
[2024-11-02T22:18:48Z INFO  rust_script] generating Cargo package...
[2024-11-02T22:18:48Z DEBUG rust_script] overwrite_file("/home/username/.cache/rust-script/projects/757b44cade3c09a2f7355d82/Cargo.toml", _)
[2024-11-02T22:18:48Z DEBUG rust_script] Equal content
[2024-11-02T22:18:48Z INFO  rust_script] disarming pkg dir cleanup...
[2024-11-02T22:18:48Z DEBUG rust_script] No old binary found
   Compiling example_757b44cade3c09a2f7355d82 v0.1.0 (/home/username/.cache/rust-script/projects/757b44cade3c09a2f7355d82)
error[E0433]: failed to resolve: use of undeclared crate or module `time`
  --> /home/username/example.ers:16:20
   |
16 |     println!("{}", time::now().rfc822z());
   |                    ^^^^ use of undeclared crate or module `time`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `example_757b44cade3c09a2f7355d82` (bin "example_757b44cade3c09a2f7355d82") due to 1 previous error
[2024-11-02T22:18:48Z INFO  rust_script] cleaning cache with max_age: 604800000
[2024-11-02T22:18:48Z INFO  rust_script] cutoff:            1729981128361 ms
[2024-11-02T22:18:48Z INFO  rust_script] checking: "/home/username/.cache/rust-script/projects/757b44cade3c09a2f7355d82"
[2024-11-02T22:18:48Z INFO  rust_script] meta_mtime:        1730585737204 ms
[2024-11-02T22:18:48Z INFO  rust_script] done cleaning cache.
error: Could not execute cargo

No matter what I do, dependencies in generated toml is empty

@andar1an andar1an changed the title Example Dependencies Don't seem to be working Example dependencies don't seem to be working Nov 2, 2024
@andar1an
Copy link
Author

andar1an commented Nov 2, 2024

I had single line comments before the cargo doc comments to direct to links for rust-script.org.

Because rust-script expects the first single line comment to be a type of dependency, the following dependencies were not being used.

Moving the cargo fence to just after hash-bang corrected issue.

@andar1an andar1an closed this as completed Nov 2, 2024
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

1 participant