tools-build

2021-10-05T20:52:39.447800Z

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

2021-10-05T20:53:10.448700Z

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

Alex Miller (Clojure team) 2021-10-05T20:53:28.449100Z

Why would it matter?

2021-10-05T20:53:28.449200Z

it is on my classpath

2021-10-05T20:53:47.449400Z

(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.

Alex Miller (Clojure team) 2021-10-05T20:57:15.453100Z

There's a trailing space in that string btw

Alex Miller (Clojure team) 2021-10-05T20:57:36.453800Z

If you really have that, this won't work

2021-10-05T21:02:07.455300Z

it went

2021-10-05T21:02:08.455500Z

!!

2021-10-05T21:02:09.455700Z

sorry

2021-10-05T20:54:09.449800Z

when I do this at the repl with this deps

2021-10-05T20:54:22.450400Z

I don't know why it would matter

Alex Miller (Clojure team) 2021-10-05T20:54:24.450500Z

How did you start the repl?

2021-10-05T20:55:10.451200Z

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

Alex Miller (Clojure team) 2021-10-05T20:56:00.452200Z

What is the full alias in deps.edn?

2021-10-05T20:57:12.452900Z

{: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"}}}}}

2021-10-05T20:57:42.454Z

Alex Miller (Clojure team) 2021-10-05T21:00:06.454700Z

Seems like that should work

Alex Miller (Clojure team) 2021-10-05T21:00:20.455200Z

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

👍 1
2021-10-05T21:03:55.456400Z

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

2021-10-05T21:04:28.456900Z

instead of being in "src"?

seancorfield 2021-10-05T21:05:12.457600Z

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

seancorfield 2021-10-05T21:05:23.457900Z

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

seancorfield 2021-10-05T21:06:12.458900Z

(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)

seancorfield 2021-10-05T21:07:12.459500Z

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

borkdude 2021-10-05T21:08:56.460Z

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)

2021-10-05T21:09:33.460400Z

I have this on build.clj

2021-10-05T21:09:56.460600Z

(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)

thheller 2021-10-06T05:03:09.474600Z

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

👍 1
2021-10-05T21:10:08.461Z

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

2021-10-05T21:10:22.461400Z

[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

2021-10-05T21:10:26.461600Z

it returned this

2021-10-05T21:15:54.462300Z

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

2021-10-05T21:16:40.462900Z

2021-10-05T21:17:10.463700Z

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

2021-10-05T21:17:39.464300Z

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

2021-10-05T21:18:13.465Z

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

2021-10-05T21:18:16.465200Z

😅

borkdude 2021-10-05T21:20:23.466300Z

@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.

2021-10-05T21:27:00.471600Z

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

2021-10-05T21:27:34.471800Z

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

seancorfield 2021-10-05T21:21:36.466900Z

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

2021-10-06T12:54:47.475600Z

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

2021-10-06T12:55:11.475800Z

or you put into the root folder of the project?

2021-10-06T12:55:54.476Z

oh, it's in the root folder

2021-10-06T12:58:38.476200Z

thanks @seancorfield it went right 😄

👍🏻 1
seancorfield 2021-10-06T15:21:42.476500Z

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?)

2021-10-07T13:45:34.483200Z

I think it needs to be more clear about that

seancorfield 2021-10-07T21:54:32.483600Z

@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.

1
2021-10-08T17:32:55.488800Z

Nice, thanks Sean!

2021-10-05T21:30:12.472Z

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

2021-10-05T21:30:15.472200Z

it gave me

2021-10-05T21:30:16.472400Z

[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.

2021-10-05T21:30:19.472600Z

same error 😞

seancorfield 2021-10-05T22:14:55.473700Z

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.

seancorfield 2021-10-05T22:16:24.473900Z

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
seancorfield 2021-10-05T22:25:45.474100Z

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

seancorfield 2021-10-05T22:27:36.474400Z

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

👍 1
seancorfield 2021-10-05T21:22:40.467900Z

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).

2021-10-05T21:31:59.472900Z

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.

2021-10-05T21:32:02.473100Z

again 😞

seancorfield 2021-10-05T21:23:12.468600Z

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

2021-10-05T21:23:38.468900Z

Clojure CLI version 1.10.3.986

seancorfield 2021-10-05T21:25:47.471400Z

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.

borkdude 2021-10-05T21:23:19.468800Z

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

seancorfield 2021-10-05T21:24:06.469500Z

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

borkdude 2021-10-05T21:24:16.469900Z

got it

seancorfield 2021-10-05T21:24:52.470600Z

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.

2021-10-05T21:25:38.471Z

I did that to try it on cursive repl only

2021-10-05T21:25:41.471200Z

thanks