Fork me on GitHub
#tools-build
<
2021-10-05
>
Ian Fernandez20:10:39

anyone tried to use tools.build on a Mac M1?

Ian Fernandez20:10:10

with io.github.clojure/tools.build {:git/tag "v0.5.1" :git/sha "21da7d4"} I've tried to see that if it is in my classpath

alexmiller20:10:28

Why would it matter?

Ian Fernandez20:10:28

it is on my classpath

Ian Fernandez20:10:47

(slurp (http://clojure.java.io/resource "clojure/tools/build/api.clj ")) Execution error (IllegalArgumentException) at user/eval26714 (form-init3758113223764110517.clj:1). Cannot open <nil> as a Reader.

alexmiller20:10:15

There's a trailing space in that string btw

alexmiller20:10:36

If you really have that, this won't work

Ian Fernandez20:10:09

when I do this at the repl with this deps

Ian Fernandez20:10:22

I don't know why it would matter

alexmiller20:10:24

How did you start the repl?

Ian Fernandez20:10:10

by IntelliJ classpath, with tool.deps adding the alias that has the build

alexmiller20:10:00

What is the full alias in deps.edn?

Ian Fernandez20:10:12

{:paths ["src" "test" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.3"}
        io.pedestal/pedestal.service {:mvn/version "0.5.9"}
        io.pedestal/pedestal.jetty   {:mvn/version "0.5.9"}
        reagent/reagent              {:mvn/version "1.1.0"}
        nubank/workspaces            {:mvn/version "1.1.1"}
        binaryage/devtools           {:mvn/version "1.0.3"}
        borkdude/sci                 {:mvn/version "0.2.6"}
        thheller/shadow-cljs         {:mvn/version "2.15.10"}
        org.slf4j/slf4j-simple       {:mvn/version "1.7.30"}
        com.google.guava/guava {:mvn/version "31.0.1-jre"}}
 :aliases {:build {:extra-deps  {io.github.clojure/tools.build {:git/tag "v0.5.1"
                                                                :git/sha "21da7d4"}}}}}

alexmiller21:10:06

Seems like that should work

alexmiller21:10:20

Can you check that trailing space I asked about in thread?

👍 1
Ian Fernandez21:10:55

the build ns needs to be in another folder from the classpath?

Ian Fernandez21:10:28

instead of being in "src"?

seancorfield21:10:12

@d.ian.b When you run clojure -T:build ... the classpath has just the deps from :build and the path ["."]

seancorfield21:10:23

So the assumption is build.clj is in the project root.

seancorfield21:10:12

(and you'd normally have :ns-default build in the :build alias so you can invoke clojure -T:build my-fn and it will run build/my-fn)

seancorfield21:10:12

I don't think Cursive currently supports running build scripts tho'...

borkdude21:10:56

You can start a REPL in a build.clj function though and then connect to it, probably (I've done this from emacs, don't know about Cursive)

Ian Fernandez21:10:33

I have this on build.clj

Ian Fernandez21:10:56

(ns build
  (:require [clojure.tools.build.api :as b]
            [shadow.cljs.devtools.api :as shadow.api]
            [shadow.cljs.devtools.server :as shadow.server]))

(def lib 'ianffcs/project)
(def class-dir "target/classes")
(def uber-file "target/project.jar")

(defn -main
  [& _]
  (let [basis (b/create-basis {:project "deps.edn"})]
    (b/delete {:path "target"})
    (shadow.server/start!)
    (shadow.api/release :project)
    (shadow.server/stop!)
    (b/write-pom {:class-dir class-dir
                  :lib       lib
                  :version   "1.0.0"
                  :basis     basis
                  :src-dirs  (:paths basis)})
    (b/compile-clj {:basis       basis
                    :src-dirs    (:paths basis)
                    :class-dir   class-dir})
    (b/uber {:class-dir class-dir
             :main      'main
             :uber-file uber-file
             :basis     basis})
    (shutdown-agents)))

(-main)

thheller05:10:09

FWIW you do not need shadow.server/start! or stop! when only using release

👍 1
Ian Fernandez21:10:08

and I've tried to run the (-main)

Ian Fernandez21:10:22

[main] INFO org.eclipse.jetty.util.log - Logging initialized @5438ms to org.eclipse.jetty.util.log.Slf4jLog
Execution error (FileNotFoundException) at build/loading (build.clj:1).
Could not locate clojure/tools/build/api__init.class, clojure/tools/build/api.clj or clojure/tools/build/api.cljc on classpath.

Full report at:
/var/folders/vn/25ww_nmx7h7450y1c35wg8780000gn/T/clojure-12857228039568925233.edn
Syntax error (ExceptionInfo) compiling at (build.clj:31:1).
Clojure compilation failed

Full report at:
/var/folders/vn/25ww_nmx7h7450y1c35wg8780000gn/T/clojure-1488074269378056351.edn

Ian Fernandez21:10:26

it returned this

Ian Fernandez21:10:54

with this clojure -A:build -M -m build , the same error

Ian Fernandez21:10:10

with liberica-11, liberica-16 and liberica-17 on macbook m1

Ian Fernandez21:10:39

this is strange because a friend of mine is doing same stuff on linux x86 itself and it went well

Ian Fernandez21:10:13

like, I'm giving this info because my machine is "not canonical"

borkdude21:10:23

@d.ian.b You can add this function to build.clj:

(defn socket-repl [{:keys [port]}]
  ((requiring-resolve 'clojure.core.server/start-server)
   {:port port :name :repl :accept 'clojure.core.server/repl})
  (println "Started socket REPL on port" port)
  @(promise))
And then call from the command line:
clojure -T:build socket-repl :port 1337
And then connect to this server from Cursive to develop your build functions.

Ian Fernandez21:10:00

clojure -T:build socket-repl :port 1337
gives:
Unqualified function can't be resolved: socket-repl

Ian Fernandez21:10:34

clojure -T:build build/socket-repl :port 1337
gets:
Namespace could not be loaded: build

seancorfield21:10:36

@d.ian.b I wonder if your ~/.gitlibs folder is broken somehow and your git deps are not working because of that?

Ian Fernandez21:10:12

deleted .cpcache and ˜/.gitlibs and ran with clj -A:build -M -m build

Ian Fernandez21:10:16

[main] INFO org.eclipse.jetty.util.log - Logging initialized @4872ms to org.eclipse.jetty.util.log.Slf4jLog
Execution error (FileNotFoundException) at build/loading (build.clj:1).
Could not locate clojure/tools/build/api__init.class, clojure/tools/build/api.clj or clojure/tools/build/api.cljc on classpath.

Ian Fernandez21:10:19

same error 😞

seancorfield22:10:55

I think the project deps are interfering with your build script and its deps. Use clojure -T:build <function> to invoke functions in build.clj -- they will be passed a single argument, a hash map, like the -X option does.

seancorfield22:10:24

You'll need the shadow-clj dependency added to :build for that to work -- since your build.clj depends on it and :ns-default build added.

👍 1
seancorfield22:10:45

Here's what works:

(! 950)-> cat deps.edn 
{:paths ["src" "test" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.3"}
        io.pedestal/pedestal.service {:mvn/version "0.5.9"}
        io.pedestal/pedestal.jetty   {:mvn/version "0.5.9"}
        reagent/reagent              {:mvn/version "1.1.0"}
        nubank/workspaces            {:mvn/version "1.1.1"}
        binaryage/devtools           {:mvn/version "1.0.3"}
        borkdude/sci                 {:mvn/version "0.2.6"}
        thheller/shadow-cljs         {:mvn/version "2.15.10"}
        org.slf4j/slf4j-simple       {:mvn/version "1.7.30"}
        com.google.guava/guava {:mvn/version "31.0.1-jre"}}
 :aliases {:build {:deps {io.github.clojure/tools.build {:git/tag "v0.5.1" :git/sha "21da7d4"}
                          thheller/shadow-cljs {:mvn/version "2.15.10"}}
                   :ns-default build}}}

Tue Oct 05 15:23:46
(sean)-(jobs:0)-(~/clojure/fresh/fernandez)
(! 951)-> cat build.clj 
(ns build
  (:require [clojure.tools.build.api :as b]
            [shadow.cljs.devtools.api :as shadow.api]
            [shadow.cljs.devtools.server :as shadow.server]))

(def lib 'ianffcs/project)
(def class-dir "target/classes")
(def uber-file "target/project.jar")

(defn uberjar
  [_]
  (let [basis (b/create-basis {:project "deps.edn"})]
    (b/delete {:path "target"})
    (shadow.server/start!)
    (shadow.api/release :project)
    (shadow.server/stop!)
    (b/write-pom {:class-dir class-dir
                  :lib       lib
                  :version   "1.0.0"
                  :basis     basis
                  :src-dirs  (:paths basis)})
    (b/compile-clj {:basis       basis
                    :src-dirs    (:paths basis)
                    :class-dir   class-dir})
    (b/uber {:class-dir class-dir
             :main      'main
             :uber-file uber-file
             :basis     basis})
    (shutdown-agents)))

Tue Oct 05 15:23:49
(sean)-(jobs:0)-(~/clojure/fresh/fernandez)
(! 952)-> clojure -A:deps -T:build help/doc
-------------------------
build/uberjar
([_])

Tue Oct 05 15:24:10
(sean)-(jobs:0)-(~/clojure/fresh/fernandez)
(! 953)-> clojure -T:build uberjar
Oct 05, 2021 3:24:25 PM io.undertow.Undertow start
INFO: starting server: Undertow - 2.2.4.Final
Oct 05, 2021 3:24:25 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.8.0.Final
Oct 05, 2021 3:24:25 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.8.0.Final
Oct 05, 2021 3:24:25 PM org.jboss.threads.Version <clinit>
INFO: JBoss Threads version 3.1.0.Final
shadow-cljs - server version: 2.15.10 running at 
shadow-cljs - nREPL server started on port 61002
No configuration for build ":project" found.
Oct 05, 2021 3:24:28 PM io.undertow.Undertow stop
INFO: stopping server: Undertow - 2.2.4.Final
Skipping paths: test resources

Tue Oct 05 15:25:19
(sean)-(jobs:0)-(~/clojure/fresh/fernandez)
(! 954)-> 

seancorfield22:10:36

(obvs it couldn't find the :project build coz I don't have the shadow-cljs config)

👍 1
Ian Fernandez12:10:47

my build is in ./src/build.clj is this correct?

Ian Fernandez12:10:11

or you put into the root folder of the project?

Ian Fernandez12:10:54

oh, it's in the root folder

Ian Fernandez12:10:38

thanks @U04V70XH6 it went right 😄

1
seancorfield15:10:42

build.clj is not part of your application so it shouldn't live in src. Do you think the tools.build guide could be clearer about that? (and also to use :deps instead of :extra-deps and -T:build instead of -A/`-M` or was that just your attempt to satisfy Cursive?)

Ian Fernandez13:10:34

I think it needs to be more clear about that

seancorfield21:10:32

@d.ian.b There's already an issue for this https://github.com/clojure/clojure-site/issues/550 so I've tried to summarize what I think you found confusing/missing there. Feel free to add more comments if I missed anything.

clojure-spin 1
Ian Fernandez17:10:55

Nice, thanks Sean!

seancorfield21:10:40

Maybe delete that folder and also the .cpcache folder in your project and try that clojure -M:build -m build command again (you don't need -A:build separately, you can put the alias on -M).

Ian Fernandez21:10:59

clojure -M:build -m build => I got the Could not locate clojure/tools/build/api__init.class, clojure/tools/build/api.clj or clojure/tools/build/api.cljc on classpath.

seancorfield21:10:12

Also, confirm that your installed clojure command is recent enough: clojure -version -- what version do you get?

Ian Fernandez21:10:38

Clojure CLI version 1.10.3.986

seancorfield21:10:47

OK, so you could use -T and follow the guide -- which means having an exec function style entry point into your build.clj instead of -main.

borkdude21:10:19

Does -M work with :deps -- is :deps a synonym for :replace-deps now?

seancorfield21:10:06

He isn't using -T to invoke it and he doesn't have :deps in :build -- he has :extra-deps.

seancorfield21:10:52

Also, @d.ian.b you have a call to -main at the bottom of your build.clj so that is going to run -main when the ns is loaded which is going to defeat almost everything you try to do with it.

Ian Fernandez21:10:38

I did that to try it on cursive repl only