Skip to content

rustic-babel: Can't set local crate path in src block #70

@EnigmaCurry

Description

@EnigmaCurry

I am trying to add my own crate with the :paths argument in rustic-babel code block:

#+begin_src rust :main no :results value drawer :exports true :linenos true :paths '((lib "/home/ryan/git/vendor/enigmacurry/org/src/rust/lib")) :crates '((lib . 1.0))
  use lib::*;
  use lib::plotters::prelude::*;

  fn main() -> Result<(), Box<dyn std::error::Error>> {
      // Get new static file path for ox-hugo export:
      let full_path = get_static_file("chart.png")?;
      let rel_path = get_static_file_url(&full_path)?;
      
      // Create the chart and save it
      let root = BitMapBackend::new(&full_path, (640, 480)).into_drawing_area();
      root.fill(&WHITE)?;

      let mut chart = ChartBuilder::on(&root)
          .caption("Line Chart Example", ("sans-serif", 50))
          .margin(10)
          .x_label_area_size(30)
          .y_label_area_size(30)
          .build_cartesian_2d(0..10, 0..10)?;

      chart.configure_mesh().draw()?;

      chart
          .draw_series(LineSeries::new(
              (0..10).map(|x| (x, x * x)),
              &RED,
          ))?
          .label("y = x^2")
          .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED));

      chart.configure_series_labels().draw()?;

      println!("[[{}]]", rel_path);

      Ok(())
  }
#+end_src

Heres the traceback from executing this block:

Debugger entered--Lisp error: (wrong-type-argument characterp "/home/ryan/git/vendor/enigmacurry/org/src/rust/lib")
  crate-dependencies("lib" "1.0" nil ("/home/ryan/git/vendor/enigmacurry/org/src/rust/lib"))
  (let ((cargo-toml-entry (crate-dependencies name version features path))) (setq dependencies (concat dependencies cargo-toml-entry "\n")))
  (let* ((name (if (listp crate-and-version) (car crate-and-version) crate-and-version)) (version (if (listp crate-and-version) (cdr crate-and-version) "*")) (features (cdr (assoc name crate-features))) (path (cdr (assoc name crate-paths)))) (if (symbolp name) (progn (setq name (symbol-name name)))) (if (numberp version) (progn (setq version (number-to-string version)))) (if (symbolp version) (progn (setq version (symbol-name version)))) (if (not (listp features)) (progn (setq features (list features)))) (let ((cargo-toml-entry (crate-dependencies name version features path))) (setq dependencies (concat dependencies cargo-toml-entry "\n"))))
  (let ((crate-and-version (car tail))) (let* ((name (if (listp crate-and-version) (car crate-and-version) crate-and-version)) (version (if (listp crate-and-version) (cdr crate-and-version) "*")) (features (cdr (assoc name crate-features))) (path (cdr (assoc name crate-paths)))) (if (symbolp name) (progn (setq name (symbol-name name)))) (if (numberp version) (progn (setq version (number-to-string version)))) (if (symbolp version) (progn (setq version (symbol-name version)))) (if (not (listp features)) (progn (setq features (list features)))) (let ((cargo-toml-entry (crate-dependencies name version features path))) (setq dependencies (concat dependencies cargo-toml-entry "\n")))) (setq tail (cdr tail)))
  (while tail (let ((crate-and-version (car tail))) (let* ((name (if (listp crate-and-version) (car crate-and-version) crate-and-version)) (version (if (listp crate-and-version) (cdr crate-and-version) "*")) (features (cdr (assoc name crate-features))) (path (cdr (assoc name crate-paths)))) (if (symbolp name) (progn (setq name (symbol-name name)))) (if (numberp version) (progn (setq version (number-to-string version)))) (if (symbolp version) (progn (setq version (symbol-name version)))) (if (not (listp features)) (progn (setq features (list features)))) (let ((cargo-toml-entry (crate-dependencies name version features path))) (setq dependencies (concat dependencies cargo-toml-entry "\n")))) (setq tail (cdr tail))))
  (let ((tail crate-versions)) (while tail (let ((crate-and-version (car tail))) (let* ((name (if (listp crate-and-version) (car crate-and-version) crate-and-version)) (version (if (listp crate-and-version) (cdr crate-and-version) "*")) (features (cdr (assoc name crate-features))) (path (cdr (assoc name crate-paths)))) (if (symbolp name) (progn (setq name (symbol-name name)))) (if (numberp version) (progn (setq version (number-to-string version)))) (if (symbolp version) (progn (setq version (symbol-name version)))) (if (not (listp features)) (progn (setq features (list features)))) (let ((cargo-toml-entry (crate-dependencies name version features path))) (setq dependencies (concat dependencies cargo-toml-entry "\n")))) (setq tail (cdr tail)))))
  (let ((dependencies "")) (let ((tail crate-versions)) (while tail (let ((crate-and-version (car tail))) (let* ((name (if ... ... crate-and-version)) (version (if ... ... "*")) (features (cdr ...)) (path (cdr ...))) (if (symbolp name) (progn (setq name ...))) (if (numberp version) (progn (setq version ...))) (if (symbolp version) (progn (setq version ...))) (if (not (listp features)) (progn (setq features ...))) (let ((cargo-toml-entry ...)) (setq dependencies (concat dependencies cargo-toml-entry "\n")))) (setq tail (cdr tail))))) (setq dependencies (concat "[dependencies]\n" dependencies)))
  cargo-toml-dependencies(((lib . 1.0)) nil ((lib "/home/ryan/git/vendor/enigmacurry/org/src/rust/lib")))
  rustic-babel-cargo-toml("/tmp/babel-DszpZ2/cargo8LiA36" ((:colname-names) (:rowname-names) (:result-params "replace" "value" "drawer") (:result-type . value) (:results . "replace value drawer") (:exports . "code true") (:session . "none") (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no") (:main . "no") (:linenos . "true") (:paths (lib "/home/ryan/git/vendor/enigmacurry/org/src/rust/lib")) (:crates (lib . 1.0))))
  org-babel-execute:rust("use lib::*;\nuse lib::plotters::prelude::*;\n\nfn mai..." ((:colname-names) (:rowname-names) (:result-params "replace" "value" "drawer") (:result-type . value) (:results . "replace value drawer") (:exports . "code true") (:session . "none") (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no") (:main . "no") (:linenos . "true") (:paths (lib "/home/ryan/git/vendor/enigmacurry/org/src/rust/lib")) (:crates (lib . 1.0))))
  org-babel-execute-src-block(nil ("rust" "use lib::*;\nuse lib::plotters::prelude::*;\n\nfn mai..." ((:colname-names) (:rowname-names) (:result-params "drawer" "value" "replace") (:result-type . value) (:results . "drawer value replace") (:exports . "true code") (:crates (lib . 1.0)) (:paths (lib "/home/ryan/git/vendor/enigmacurry/org/src/rust/lib")) (:linenos . "true") (:main . "no") (:tangle . "no") (:hlines . "no") (:noweb . "no") (:cache . "no") (:session . "none")) "" nil 800 "(ref:%s)"))
  org-ctrl-c-ctrl-c(nil)
  funcall-interactively(org-ctrl-c-ctrl-c nil)
  command-execute(org-ctrl-c-ctrl-c)
  • Apparent problem

It looks like the function crate-dependencies is receiving a path list, but it expects a single path string. I have a fix for this I will make in a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions