Skip to content

Commit

Permalink
Clean up CLI and Add formatter (#866)
Browse files Browse the repository at this point in the history
* Add shlangbox tool

* Add formatter logic

* Formatter improvements

* Cleanup

* Cleanup

* Cleanup & simplify

* Fix inline and commments with ; in them

* Fix namespaces being stripped

* Fix missing interpolations

* Cleaner formatting for expr & const_expr

* Fix whitespace around argumentless builtins

* Fix cases of spawning recursive newlines

* Add test cases

* Embed formatter into lang crate

* Add option to build without rust union

* Cleanup formatter. Add formatter tests

* Add expected test results & compare ignore eol

* Flush stdout when formatting to stdout

* Add missing rust lib

* Fix CLI when running clj

* Ad old 'ast' command for backwards compatibility

* Fix test command
  • Loading branch information
guusw authored Nov 21, 2023
1 parent 915a306 commit 1709db9
Show file tree
Hide file tree
Showing 37 changed files with 1,658 additions and 200 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ jobs:
cd build
ninja test-runtime
./test-runtime
- name: Test Tools
env:
RUST_BACKTRACE: full
run: |
cmake --build build --target shards
SH=`pwd`/build/shards
echo "Running language formatter tests"
cd shards/lang/src/tests
$SH test
# Minimize disk usage to prevent the next steps getting stuck due to no disk space
- name: Minimize disk usage
env:
Expand Down
112 changes: 61 additions & 51 deletions cmake/Modules.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
option(SHARDS_WITH_EVERYTHING "Enables all modules, disabling this will only build common modules and exclude experimental ones" ON)
option(SHARDS_NO_RUST_UNION "Disables rust union build" OFF)

function(is_module_enabled OUTPUT_VARIABLE MODULE_ID)
if(${SHARDS_WITH_EVERYTHING})
Expand Down Expand Up @@ -132,68 +133,77 @@ function(shards_generate_rust_union TARGET_NAME)

list(APPEND RUST_TARGETS ${UNION_EXTRA_RUST_TARGETS})

set(GEN_RUST_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME})
set(GEN_RUST_SRC_PATH ${GEN_RUST_PATH}/src)
set(CARGO_TOML ${GEN_RUST_PATH}/Cargo.toml)
set(LIB_RS_TMP ${GEN_RUST_SRC_PATH}/lib.rs.tmp)
set(LIB_RS ${GEN_RUST_SRC_PATH}/lib.rs)

file(MAKE_DIRECTORY ${GEN_RUST_SRC_PATH})
file(WRITE ${LIB_RS_TMP} "// This file is generated by CMake\n\n")

# Add all the rust targets to the Cargo.toml
foreach(RUST_TARGET ${RUST_TARGETS})
get_property(RUST_PROJECT_PATH TARGET ${RUST_TARGET} PROPERTY RUST_PROJECT_PATH)
get_property(RUST_NAME TARGET ${RUST_TARGET} PROPERTY RUST_NAME)

get_property(RUST_FEATURES TARGET ${RUST_TARGET} PROPERTY RUST_FEATURES)
unset(RUST_FEATURES_STRING)
unset(RUST_FEATURES_STRING1)
if(RUST_FEATURES)
unset(RUST_FEATURES_QUOTED)
foreach(FEATURE ${RUST_FEATURES})
list(APPEND RUST_FEATURES_QUOTED \"${FEATURE}\")
endforeach()
list(JOIN RUST_FEATURES_QUOTED "," RUST_FEATURES_STRING)
set(RUST_FEATURES_STRING1 ", features = [${RUST_FEATURES_STRING}]")
endif()
# Disable union
if(SHARDS_NO_RUST_UNION)
add_library(${TARGET_NAME} INTERFACE)
foreach(RUST_TARGET ${RUST_TARGETS})
message(STATUS "RUST TARGET: ${RUST_TARGET}")
target_link_libraries(${TARGET_NAME} INTERFACE ${RUST_TARGET})
endforeach()
else()
set(GEN_RUST_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME})
set(GEN_RUST_SRC_PATH ${GEN_RUST_PATH}/src)
set(CARGO_TOML ${GEN_RUST_PATH}/Cargo.toml)
set(LIB_RS_TMP ${GEN_RUST_SRC_PATH}/lib.rs.tmp)
set(LIB_RS ${GEN_RUST_SRC_PATH}/lib.rs)

file(MAKE_DIRECTORY ${GEN_RUST_SRC_PATH})
file(WRITE ${LIB_RS_TMP} "// This file is generated by CMake\n\n")

# Add all the rust targets to the Cargo.toml
foreach(RUST_TARGET ${RUST_TARGETS})
get_property(RUST_PROJECT_PATH TARGET ${RUST_TARGET} PROPERTY RUST_PROJECT_PATH)
get_property(RUST_NAME TARGET ${RUST_TARGET} PROPERTY RUST_NAME)

get_property(RUST_FEATURES TARGET ${RUST_TARGET} PROPERTY RUST_FEATURES)
unset(RUST_FEATURES_STRING)
unset(RUST_FEATURES_STRING1)
if(RUST_FEATURES)
unset(RUST_FEATURES_QUOTED)
foreach(FEATURE ${RUST_FEATURES})
list(APPEND RUST_FEATURES_QUOTED \"${FEATURE}\")
endforeach()
list(JOIN RUST_FEATURES_QUOTED "," RUST_FEATURES_STRING)
set(RUST_FEATURES_STRING1 ", features = [${RUST_FEATURES_STRING}]")
endif()

message(VERBOSE "${TARGET_NAME}: Adding rust target ${RUST_TARGET} (path: ${RUST_PROJECT_PATH}, name: ${RUST_NAME}, features: ${RUST_FEATURES_STRING})")
message(VERBOSE "${TARGET_NAME}: Adding rust target ${RUST_TARGET} (path: ${RUST_PROJECT_PATH}, name: ${RUST_NAME}, features: ${RUST_FEATURES_STRING})")

file(RELATIVE_PATH RELATIVE_RUST_PROJECT_PATH ${GEN_RUST_PATH} ${RUST_PROJECT_PATH})
string(APPEND CARGO_CRATE_DEPS "${RUST_NAME} = { path = \"${RELATIVE_RUST_PROJECT_PATH}\"${RUST_FEATURES_STRING1} }\n")
file(RELATIVE_PATH RELATIVE_RUST_PROJECT_PATH ${GEN_RUST_PATH} ${RUST_PROJECT_PATH})
string(APPEND CARGO_CRATE_DEPS "${RUST_NAME} = { path = \"${RELATIVE_RUST_PROJECT_PATH}\"${RUST_FEATURES_STRING1} }\n")

string(REPLACE "-" "_" RUST_NAME_ID ${RUST_NAME})
file(APPEND ${LIB_RS_TMP} "pub use ${RUST_NAME_ID};\n")
string(REPLACE "-" "_" RUST_NAME_ID ${RUST_NAME})
file(APPEND ${LIB_RS_TMP} "pub use ${RUST_NAME_ID};\n")

get_property(TARGET_INTERFACE_LINK_LIBRARIES TARGET ${RUST_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES)
list(APPEND COMBINED_INTERFACE_LINK_LIBRARIES ${TARGET_INTERFACE_LINK_LIBRARIES})
get_property(TARGET_INTERFACE_LINK_LIBRARIES TARGET ${RUST_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES)
list(APPEND COMBINED_INTERFACE_LINK_LIBRARIES ${TARGET_INTERFACE_LINK_LIBRARIES})

get_property(RUST_DEPENDS TARGET ${RUST_TARGET} PROPERTY RUST_DEPENDS)
list(APPEND COMBINED_RUST_DEPENDS ${RUST_DEPENDS})
get_property(RUST_DEPENDS TARGET ${RUST_TARGET} PROPERTY RUST_DEPENDS)
list(APPEND COMBINED_RUST_DEPENDS ${RUST_DEPENDS})

get_property(RUST_ENVIRONMENT TARGET ${RUST_TARGET} PROPERTY RUST_ENVIRONMENT)
list(APPEND COMBINED_RUST_ENVIRONMENT ${RUST_ENVIRONMENT})
endforeach()
get_property(RUST_ENVIRONMENT TARGET ${RUST_TARGET} PROPERTY RUST_ENVIRONMENT)
list(APPEND COMBINED_RUST_ENVIRONMENT ${RUST_ENVIRONMENT})
endforeach()

# The generated create name
set(CARGO_CRATE_NAME ${TARGET_NAME})
# The generated create name
set(CARGO_CRATE_NAME ${TARGET_NAME})

file(COPY_FILE ${LIB_RS_TMP} ${LIB_RS} ONLY_IF_DIFFERENT)
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Cargo.toml.in" ${CARGO_TOML})
file(COPY_FILE ${LIB_RS_TMP} ${LIB_RS} ONLY_IF_DIFFERENT)
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Cargo.toml.in" ${CARGO_TOML})

# Add the rust library
add_rust_library(NAME ${TARGET_NAME}
PROJECT_PATH ${GEN_RUST_PATH}
DEPENDS ${COMBINED_RUST_DEPENDS}
ENVIRONMENT ${COMBINED_RUST_ENVIRONMENT})
add_library(${TARGET_NAME} ALIAS ${TARGET_NAME}-rust)
# Add the rust library
add_rust_library(NAME ${TARGET_NAME}
PROJECT_PATH ${GEN_RUST_PATH}
DEPENDS ${COMBINED_RUST_DEPENDS}
ENVIRONMENT ${COMBINED_RUST_ENVIRONMENT})
add_library(${TARGET_NAME} ALIAS ${TARGET_NAME}-rust)

list(REMOVE_DUPLICATES COMBINED_INTERFACE_LINK_LIBRARIES)
list(REMOVE_DUPLICATES COMBINED_INTERFACE_LINK_LIBRARIES)

if(COMBINED_INTERFACE_LINK_LIBRARIES)
set_property(TARGET ${TARGET_NAME}-rust APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${COMBINED_INTERFACE_LINK_LIBRARIES})
message(VERBOSE "${TARGET_NAME}: Linking against ${COMBINED_INTERFACE_LINK_LIBRARIES}")
if(COMBINED_INTERFACE_LINK_LIBRARIES)
set_property(TARGET ${TARGET_NAME}-rust APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${COMBINED_INTERFACE_LINK_LIBRARIES})
message(VERBOSE "${TARGET_NAME}: Linking against ${COMBINED_INTERFACE_LINK_LIBRARIES}")
endif()
endif()
endfunction()

Expand Down
1 change: 0 additions & 1 deletion cmake/Root.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ add_subdirectory(${SHARDS_DIR}/shards/lang src/lang)

# Rust projects
add_subdirectory(${SHARDS_DIR}/shards/rust src/rust)
add_subdirectory(${SHARDS_DIR}/shards/rust_macro src/rust_macro)

# Modules
set(SHARDS_MODULE_ROOT ${SHARDS_DIR}/shards/modules)
Expand Down
2 changes: 1 addition & 1 deletion cmake/Rust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function(add_rust_library)

# Add default required libraries for windows
if(WIN32)
target_link_libraries(${RUST_TARGET_NAME} INTERFACE NtDll)
target_link_libraries(${RUST_TARGET_NAME} INTERFACE NtDll Userenv)
endif()
endfunction()

Expand Down
2 changes: 1 addition & 1 deletion shards/egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ egui = { version = "0.22.0", features = ["persistence"] }
egui_commonmark = { version = "0.7.3" }
egui_dock = { version = "0.6.1" }
egui_extras = { version = "0.22.0" }
egui_memory_editor = { version = "0.2.4" }
egui_memory_editor = { version = "=0.2.5" }
syntect = { version = "5.0.0", default-features = false, features = [
"default-fancy",
] }
Expand Down
2 changes: 1 addition & 1 deletion shards/lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ serde = { version = "1.0", features = ["derive"] }
shards = { path = "../rust" }
hex = { version = "0.4.3" }
nanoid = "0.4.0"
clap = "4.3.9"
clap = { version = "4.4.7", features = ["derive"] }
profiling = { version = "1", default-features = false }
compile-time-crc32 = "0.1.2"
lazy_static = "1.4.0"
Expand Down
Loading

0 comments on commit 1709db9

Please sign in to comment.