From 3c192fbabed9714482ceb09a982f76ec8969b12d Mon Sep 17 00:00:00 2001 From: mlatu Date: Sat, 13 Jan 2024 02:18:19 +0100 Subject: [PATCH 1/8] now builds without the libprefix and static and test runs too now --- CMakeLists.txt | 8 ++++++++ test.janet | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3936f14..dc788e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,10 @@ cmake_minimum_required(VERSION 3.7) project(janetui) +set(CMAKE_SHARED_LIBRARY_PREFIX "") +set(CMAKE_SHARED_MODULE_PREFIX "") +set(CMAKE_STATIC_LIBRARY_PREFIX "") + # Set Some Variables set(TARGET_NAME ${PROJECT_NAME}) set(CMAKE_C_STANDARD 99) @@ -47,3 +51,7 @@ set(_COMMON_LDFLAGS "") # Build our library add_library(${TARGET_NAME} MODULE ${SOURCES}) target_link_libraries(${TARGET_NAME} libui glib-2.0 gtk-3 gdk-3) + +add_library("${TARGET_NAME}STATIC" STATIC ${SOURCES}) +target_link_libraries("${TARGET_NAME}STATIC" libui glib-2.0 gtk-3 gdk-3) +set_target_properties("${TARGET_NAME}STATIC" PROPERTIES OUTPUT_NAME ${TARGET_NAME}) \ No newline at end of file diff --git a/test.janet b/test.janet index ac11bea..5378693 100755 --- a/test.janet +++ b/test.janet @@ -1,6 +1,6 @@ #!/usr/bin/env janet -(import build/libjanetui :as ui) +(import ./build/libjanetui :as ui) (def menu (ui/menu "File")) From 9aa17fd16d6e05613415720c7dfe6739453a9146 Mon Sep 17 00:00:00 2001 From: mlatu Date: Sat, 4 May 2024 00:56:56 +0200 Subject: [PATCH 2/8] uh, build twice to get a better result :shrug: --- project.janet | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/project.janet b/project.janet index e85ec80..e69cbf4 100644 --- a/project.janet +++ b/project.janet @@ -4,13 +4,46 @@ :url "https://github.com/janet-lang/janetui" :repo "https://github.com/janet-lang/janetui.git") -(rule "build/janetui.so" ["CMakeLists.txt"] +(def o (os/which)) + +(def cflags + (case o + :macos '["-Ilibui" "-Ilibui/darwin"] + :windows ["-Ilibui" "-Ilibui/windows" ] + #default + '["-Ilibui" "-Ilibui/unix"])) + +(def lflags + (case o + :linux '[ "build/libui/out/ui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"] + #default + '[ "build/libui/out/ui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"])) + + +(declare-bin + :main "./build/janetui.so") + +(rule "cmake" ["CMakeLists.txt"] (do - (os/mkdir "build") - (os/cd "build") - (os/execute ["cmake" ".."] :p) (assert - (zero? - (os/execute ["make"] :p))))) + (and + (zero? + (os/execute ["cmake" "-B" "build"] :p)) + (zero? + (os/execute ["cmake" "--build" "build"] :p)) "--build build")))) + +(add-input "build" "cmake") +(add-output "cmake" "build/libui/out/ui.a") + +(declare-native + :name "janetui" + :source ["main.c"] + :cflags [;default-cflags ;cflags] + :lflags [;default-lflags ;lflags]) -(add-dep "build" "build/janetui.so") +(comment +(declare-executable + :name "uwudemo" + :entry "test.janet" + :install false) +) \ No newline at end of file From 6012285cddf60be0a362832a87ae53a9c54a2f02 Mon Sep 17 00:00:00 2001 From: mlatu Date: Sat, 4 May 2024 13:47:59 +0200 Subject: [PATCH 3/8] example of a tool in doc-me-this.janet --- doc-me-this.janet | 20 ++++++++++++++++++++ project.janet | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 doc-me-this.janet diff --git a/doc-me-this.janet b/doc-me-this.janet new file mode 100644 index 0000000..7456386 --- /dev/null +++ b/doc-me-this.janet @@ -0,0 +1,20 @@ +(import janetui :as ui) + +(defn main [& args] + (let [w (ui/window "doc-me-this" 500 250 true) + outerbox (ui/vertical-box) + entrybox (ui/search-entry ) + biglabel (ui/multiline-entry)] + (ui/entry/on-changed entrybox |(let [entry (ui/entry/text entrybox) + doctext (let [buffer (buffer/new 4096)] + (with-dyns [*out* buffer] + (when (> (length entry) 0) + (doc* entry) + (doc* (symbol entry)))) + (string buffer))] + (ui/multiline-entry/text biglabel doctext))) + (ui/box/append outerbox entrybox) + (ui/box/append outerbox biglabel true) + (ui/window/set-child w outerbox) + (ui/show w)) + (ui/main)) \ No newline at end of file diff --git a/project.janet b/project.janet index e69cbf4..0eda211 100644 --- a/project.janet +++ b/project.janet @@ -41,6 +41,11 @@ :cflags [;default-cflags ;cflags] :lflags [;default-lflags ;lflags]) + +#(declare-executable +# :name "doc-me-this" +# :entry "doc-me-this.janet") + (comment (declare-executable :name "uwudemo" From 87c75b61271dd3c06058e70a12a50c9dfd3e293d Mon Sep 17 00:00:00 2001 From: mlatu Date: Sun, 5 May 2024 22:14:55 +0200 Subject: [PATCH 4/8] inspired by sogaiu's simple master project.janet and iacore's clever techinque of using cmake correctly --- project.janet | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/project.janet b/project.janet index 0eda211..88dea5a 100644 --- a/project.janet +++ b/project.janet @@ -6,24 +6,7 @@ (def o (os/which)) -(def cflags - (case o - :macos '["-Ilibui" "-Ilibui/darwin"] - :windows ["-Ilibui" "-Ilibui/windows" ] - #default - '["-Ilibui" "-Ilibui/unix"])) - -(def lflags - (case o - :linux '[ "build/libui/out/ui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"] - #default - '[ "build/libui/out/ui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"])) - - -(declare-bin - :main "./build/janetui.so") - -(rule "cmake" ["CMakeLists.txt"] +(rule "build/janetui.so" ["CMakeLists.txt"] (do (assert (and @@ -32,14 +15,20 @@ (zero? (os/execute ["cmake" "--build" "build"] :p)) "--build build")))) -(add-input "build" "cmake") -(add-output "cmake" "build/libui/out/ui.a") +(add-dep "build" "build/janetui.so") (declare-native :name "janetui" :source ["main.c"] - :cflags [;default-cflags ;cflags] - :lflags [;default-lflags ;lflags]) + :cflags [;default-cflags ;(case o + :macos '["-Ilibui" "-Ilibui/darwin"] + :windows ["-Ilibui" "-Ilibui/windows" ] + #default + '["-Ilibui" "-Ilibui/unix"])] + :lflags [;default-lflags ;(case o + :linux '[ "build/libui/out/ui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"] + #default + '[ "build/libui/out/ui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"])]) #(declare-executable From 1a26e99a17c6194ce06f0cf85eea6b19fa16e0af Mon Sep 17 00:00:00 2001 From: mlatu Date: Tue, 7 May 2024 01:07:59 +0200 Subject: [PATCH 5/8] ok, lets let cmake do its thing for libui and use jpm for the native module only... --- CMakeLists.txt | 57 -------------------------------------------------- project.janet | 50 +++++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 77 deletions(-) delete mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index dc788e8..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (c) 2018 Calvin Rose -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. - -cmake_minimum_required(VERSION 3.7) -project(janetui) - -set(CMAKE_SHARED_LIBRARY_PREFIX "") -set(CMAKE_SHARED_MODULE_PREFIX "") -set(CMAKE_STATIC_LIBRARY_PREFIX "") - -# Set Some Variables -set(TARGET_NAME ${PROJECT_NAME}) -set(CMAKE_C_STANDARD 99) -set(CMAKE_C_FLAGS "${CMAKE_C_CFLAGS} -fPIC") - -# Set configurations -SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g") -SET(CMAKE_C_FLAGS_RELEASE "-O2") -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") - -set(SOURCES -main.c -) - -# Get the header ui.h -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libui) - -# Build libui as static library -set(BUILD_SHARED_LIBS OFF CACHE BOOL "") -add_subdirectory(libui) -set(_COMMON_CFLAGS "") -set(_COMMON_LDFLAGS "") - -# Build our library -add_library(${TARGET_NAME} MODULE ${SOURCES}) -target_link_libraries(${TARGET_NAME} libui glib-2.0 gtk-3 gdk-3) - -add_library("${TARGET_NAME}STATIC" STATIC ${SOURCES}) -target_link_libraries("${TARGET_NAME}STATIC" libui glib-2.0 gtk-3 gdk-3) -set_target_properties("${TARGET_NAME}STATIC" PROPERTIES OUTPUT_NAME ${TARGET_NAME}) \ No newline at end of file diff --git a/project.janet b/project.janet index 88dea5a..14e781a 100644 --- a/project.janet +++ b/project.janet @@ -5,39 +5,49 @@ :repo "https://github.com/janet-lang/janetui.git") (def o (os/which)) +(defn buildwithcmake [keyword] + (do + (pp [:START:::::: keyword]) + (pp (os/cwd)) + (os/cd "libui") + (pp (os/cwd)) + (assert + (and + (zero? + (os/execute ["cmake" "-B" "build" "-DBUILD_SHARED_LIBS=OFF"] :p)) + (zero? + (os/execute ["cmake" "--build" "build"] :p)))) + (pp (os/cwd)) + (os/cd "..") + (pp (os/cwd)) + (pp [:DONE::::::::: keyword]))) -(rule "build/janetui.so" ["CMakeLists.txt"] - (do - (assert - (and - (zero? - (os/execute ["cmake" "-B" "build"] :p)) - (zero? - (os/execute ["cmake" "--build" "build"] :p)) "--build build")))) +# when trying to not calling this in root, then the build process is jumbled around.... idk how to explain... +#comment this line to see it not finding main.c while buildwithcmake is still running: +(buildwithcmake :building-static-libui-with-cmake-now) -(add-dep "build" "build/janetui.so") +(rule "libui/build/out/libui.a" ["libui"] + (buildwithcmake :building-static-libui-with-cmake-now:WITH:::::::::::::::::RULE)) + +(add-dep "build" "libui/build/out/libui.a") (declare-native :name "janetui" :source ["main.c"] :cflags [;default-cflags ;(case o :macos '["-Ilibui" "-Ilibui/darwin"] - :windows ["-Ilibui" "-Ilibui/windows" ] + :windows '["-Ilibui" "-Ilibui/windows" ] #default '["-Ilibui" "-Ilibui/unix"])] :lflags [;default-lflags ;(case o - :linux '[ "build/libui/out/ui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"] + :linux '[ "libui/build/out/libui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"] #default - '[ "build/libui/out/ui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"])]) - - -#(declare-executable -# :name "doc-me-this" -# :entry "doc-me-this.janet") + '[ "libui/build/out/libui.a" "-lglib-2.0" "-lgtk-3" "-lgdk-3"])]) (comment (declare-executable - :name "uwudemo" - :entry "test.janet" - :install false) + :name "doc-me-this" + :entry "doc-me-this.janet" + :install false + :deps [(native-module :static)]) ) \ No newline at end of file From 9b80e068a21d15d2cc2f99bdb3b8ac0a3a158f43 Mon Sep 17 00:00:00 2001 From: mlatu Date: Tue, 7 May 2024 07:46:20 +0200 Subject: [PATCH 6/8] build with --workers=1 --- project.janet | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/project.janet b/project.janet index 14e781a..02a9e9f 100644 --- a/project.janet +++ b/project.janet @@ -4,30 +4,22 @@ :url "https://github.com/janet-lang/janetui" :repo "https://github.com/janet-lang/janetui.git") +# build with --workers=1 + (def o (os/which)) -(defn buildwithcmake [keyword] + +(defn buildwithcmake [] (do - (pp [:START:::::: keyword]) - (pp (os/cwd)) (os/cd "libui") - (pp (os/cwd)) (assert (and (zero? (os/execute ["cmake" "-B" "build" "-DBUILD_SHARED_LIBS=OFF"] :p)) (zero? - (os/execute ["cmake" "--build" "build"] :p)))) - (pp (os/cwd)) - (os/cd "..") - (pp (os/cwd)) - (pp [:DONE::::::::: keyword]))) - -# when trying to not calling this in root, then the build process is jumbled around.... idk how to explain... -#comment this line to see it not finding main.c while buildwithcmake is still running: -(buildwithcmake :building-static-libui-with-cmake-now) + (os/execute ["cmake" "--build" "build"] :p))) "! use jpm build --workers=1 !") + (os/cd ".."))) -(rule "libui/build/out/libui.a" ["libui"] - (buildwithcmake :building-static-libui-with-cmake-now:WITH:::::::::::::::::RULE)) +(rule "libui/build/out/libui.a" ["libui"] (buildwithcmake)) (add-dep "build" "libui/build/out/libui.a") From ac91a22318f3aa4776e6796daa126acadd4cadda Mon Sep 17 00:00:00 2001 From: mlatu Date: Tue, 7 May 2024 07:48:14 +0200 Subject: [PATCH 7/8] todo! make failure to build more verbose, print something about to use jpm build --workers=1 --- project.janet | 1 + 1 file changed, 1 insertion(+) diff --git a/project.janet b/project.janet index 02a9e9f..094172f 100644 --- a/project.janet +++ b/project.janet @@ -11,6 +11,7 @@ (defn buildwithcmake [] (do (os/cd "libui") + ## need to make this error more verbose (assert (and (zero? From 835ccedfba1c4f6e7c0ffa7fd250f8db76b55d1c Mon Sep 17 00:00:00 2001 From: mlatu Date: Fri, 10 May 2024 00:11:51 +0200 Subject: [PATCH 8/8] minor changes --- doc-me-this.janet | 1 + main.c | 2 +- test.janet | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc-me-this.janet b/doc-me-this.janet index 7456386..ff74f79 100644 --- a/doc-me-this.janet +++ b/doc-me-this.janet @@ -1,3 +1,4 @@ +#!/usr/bin/env janet (import janetui :as ui) (defn main [& args] diff --git a/main.c b/main.c index 83f5d17..f3fb08c 100644 --- a/main.c +++ b/main.c @@ -20,7 +20,7 @@ * IN THE SOFTWARE. */ -#include +#include #include #include diff --git a/test.janet b/test.janet index 5378693..5f872dc 100755 --- a/test.janet +++ b/test.janet @@ -1,6 +1,6 @@ #!/usr/bin/env janet -(import ./build/libjanetui :as ui) +(import ./build/janetui :as ui) (def menu (ui/menu "File"))