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

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

Closed
EnigmaCurry opened this issue Jan 6, 2025 · 2 comments
Closed

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

EnigmaCurry opened this issue Jan 6, 2025 · 2 comments

Comments

@EnigmaCurry
Copy link
Contributor

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.

@CeleritasCelery
Copy link
Contributor

The :paths parameter is an alist, meaning you need a . between the crate and the path like this:

#+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))

I see that you created a #71 to change the behavior. I think we want to keep it as is, but we still want the other improvements you added in that PR for testing.

@EnigmaCurry
Copy link
Contributor Author

Oh thank you for the explanation. Sure I can make a separate PR for the tests.

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

Successfully merging a pull request may close this issue.

2 participants