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

run-main only works on namespaces relative to where jank is #162

Closed
elken opened this issue Jan 16, 2025 · 9 comments · Fixed by jank-lang/homebrew-jank#1
Closed

run-main only works on namespaces relative to where jank is #162

elken opened this issue Jan 16, 2025 · 9 comments · Fixed by jank-lang/homebrew-jank#1
Assignees
Labels

Comments

@elken
Copy link

elken commented Jan 16, 2025

Apologies if this is already raised, I had a quick look but came up nought.

So one of the testers I asked to demo my homebrew package found out that jank run-main only seems to work when the module is relative to where jank is installed. (I'm on macos, so ignore the fact it says /private/tmp instead of /tmp, they're the same path)

Image

In this screenshot, there is a file in test/jank.jank with the below contents

(ns test.jank)

(defn count-up [max]
        (loop [count 0]
          (if (= count max)
            (println "Done!")
            (do
              (println (str "Counting " count))
              (recur (inc count))))))

(defn -main [& args]
  (count-up 5))

Doesn't work with the homebrew output build above. If I navigate to my local build instead, it does work

Image

Then if I try and call this build (I thought maybe my homebrew build didn't set something up right), it fails as before

Image

Hopefully this is enough to go on! Thanks as always 😄

@jeaye
Copy link
Member

jeaye commented Jan 16, 2025

Thanks for the detailed report.

Looks to me like we're not finding the module at all when we walk through the module paths. I'd also expect a jank --module-path "$(pwd)" repl with a (require 'test.jank) to fail similarly, if that's the case. It would also mean it's nothing to do with run-main but instead how we're walking the module paths.

Getting @Samy-33 in on this.

@Samy-33 Samy-33 self-assigned this Jan 16, 2025
@Samy-33 Samy-33 self-assigned this Jan 16, 2025
@Samy-33
Copy link
Contributor

Samy-33 commented Jan 16, 2025

Not reproducible on arch:

➜  pwd
/home/saket/tmp
➜  tree .
.
└── test
    └── jank.jank

2 directories, 1 file
➜  cat test/jank.jank
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: test/jank.jank
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ (ns test.jank)
   2   │
   3   │ (defn -main [& args]
   4   │   (println "Hello world"))
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
➜  ~/Documents/oss/jank/compiler+runtime/build/jank --module-path="$(pwd)" run-main test.jank
Bottom of clojure.core
Hello world
➜ 

@Samy-33
Copy link
Contributor

Samy-33 commented Jan 17, 2025

Followed this process on Mac M1:

  • brew tap jank-lang/jank
  • brew install jank
pwd
/Users/saket/Documents/oliv/tmp


➜  tree test
test
└── jank.jank

1 directory, 1 file


➜  cat test/jank.jank
(ns test.jank)

(defn count-up [max]
        (loop [count 0]
          (if (= count max)
            (println "Done!")
            (do
              (println (str "Counting " count))
              (recur (inc count))))))

(defn -main [& args]
  (count-up 5))


➜  jank --module-path $(pwd) run-main test.jank
Bottom of clojure.core
Counting 0
Counting 1
Counting 2
Counting 3
Counting 4
Done!

@Samy-33
Copy link
Contributor

Samy-33 commented Jan 17, 2025

Issue replicated:

➜  jank --module-path "$(pwd)" compile test.jank
Bottom of clojure.core


➜  jank --module-path "$(pwd)" run-main test.jank
Bottom of clojure.core
Exception: can't intern var; namespace doesn't exist: test.jank


➜  

@elken, can you confirm the same behaviour on your mac?

  • Remove the compiled files from the classes directory
  • Then run-main

Note: classes exists in the same directory you ran the compile command in.

@elken
Copy link
Author

elken commented Jan 17, 2025

Confirmed! That does it, you're right 😄

Image

@Samy-33
Copy link
Contributor

Samy-33 commented Jan 17, 2025

Surprisingly, jank --module-path src repl and then (require 'core) works fine.

➜  dev git:(main) ✗ pwd
/Users/saket/Documents/oss/jank/compiler+runtime/dev
➜  dev git:(main) ✗ tree .
.
├── classes
│   └── core.o
└── src
    ├── core.jank
    └── jank-lein
        └── core.clj

4 directories, 3 files
➜  dev git:(main) ✗ cat src/core.jank
(ns core)

(defn -main [& args]
  (println "Hello world"))

(println "Bottom of core")

➜  dev git:(main) ✗ which jank
/opt/homebrew/bin/jank
➜  dev git:(main) ✗ jank --module-path src repl
Bottom of clojure.core
clojure.core=> (require 'core)
Bottom of core
nil
clojure.core=> (in-ns 'core)
nil
core=> (-main)
Hello world
nil
core=>

@elken
Copy link
Author

elken commented Jan 17, 2025

Image

Yep I can repro that also

@Samy-33
Copy link
Contributor

Samy-33 commented Jan 17, 2025

The Homebrew Formual is on system-boehm branch. Building from main solved the issue. I don't have a root cause, but perhaps improvements in module loading resulted into fixing this case as well.

Thanks @elken for helping with reproduction and homebrew wizardry.

@elken
Copy link
Author

elken commented Jan 17, 2025

I think it was #155 that fixed it, it's the only obvious change since boehm was merged in

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

Successfully merging a pull request may close this issue.

3 participants