Skip to content

Commit

Permalink
feat(core): Support __eq__ and __ne__ for List/Dict (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
potatomashed committed Jan 23, 2025
1 parent 02affe5 commit 60ec306
Show file tree
Hide file tree
Showing 20 changed files with 1,102 additions and 921 deletions.
27 changes: 22 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
cmake_minimum_required(VERSION 3.15)

include(${CMAKE_CURRENT_LIST_DIR}/cmake/Utils/GitVersion.cmake)

message(STATUS "MLC VERSION: ${MLC_VERSION_GIT}")

project(
mlc
VERSION 0.1.1
MLC
VERSION ${MLC_VERSION_MAJOR}.${MLC_VERSION_MINOR}.${MLC_VERSION_PATCH}
DESCRIPTION "MLC-Python"
LANGUAGES C CXX
)
Expand All @@ -11,7 +15,7 @@ option(MLC_BUILD_TESTS "Build tests. This option will enable a test target `mlc_
option(MLC_BUILD_PY "Build Python bindings." OFF)
option(MLC_BUILD_REGISTRY
"Support for objects with non-static type indices. When turned on, \
targets linked against `mlc` will allow objects that comes with non-pre-defined type indices, \
targets linked against `MLC` will allow objects that comes with non-pre-defined type indices, \
so that the object hierarchy could expand without limitation. \
This will require the downstream targets to link against target `mlc_registry` to be effective."
OFF
Expand Down Expand Up @@ -40,9 +44,7 @@ target_include_directories(mlc INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
if (MLC_BUILD_REGISTRY)
add_library(mlc_registry_objs OBJECT
"${CMAKE_CURRENT_SOURCE_DIR}/cpp/c_api.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/cpp/c_api_tests.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/cpp/printer.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/cpp/json.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/cpp/structure.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/cpp/traceback.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/cpp/traceback_win.cc"
Expand All @@ -57,6 +59,21 @@ if (MLC_BUILD_REGISTRY)
VISIBILITY_INLINES_HIDDEN ON
PREFIX "lib"
)

string(TIMESTAMP MLC_BUILD_TIME "%Y-%m-%dT%H:%M:%S")
set_property(
SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/cpp/c_api.cc"
APPEND
PROPERTY COMPILE_DEFINITIONS
MLC_VERSION_GIT="${MLC_VERSION_GIT}"
MLC_VERSION_MAJOR="${MLC_VERSION_MAJOR}"
MLC_VERSION_MINOR="${MLC_VERSION_MINOR}"
MLC_VERSION_PATCH="${MLC_VERSION_PATCH}"
MLC_VERSION_COMMIT_NUM="${MLC_VERSION_COMMIT_NUM}"
MLC_VERSION_COMMIT_SHA="${MLC_VERSION_COMMIT_SHA}"
MLC_BUILD_TIME="${MLC_BUILD_TIME}"
)

add_cxx_warning(mlc_registry_objs)
target_link_libraries(mlc_registry_objs PRIVATE dlpack_header)
target_include_directories(mlc_registry_objs PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
Expand Down
36 changes: 36 additions & 0 deletions cmake/Utils/GitVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
find_package(Git)

if (GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _GIT_OUTPUT
RESULT_VARIABLE _GIT_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT _GIT_ERROR)
string(REGEX REPLACE "^v" "" MLC_VERSION_RAW "${_GIT_OUTPUT}")
endif()
else()
message(ERROR "Git not found, cannot determine version. Falling back to 0.0.0-0-unknown.")
endif()

if(NOT DEFINED MLC_VERSION_RAW)
set(MLC_VERSION_RAW 0.0.0-0-unknown)
message(WARNING "Failed to determine MLC_VERSION_RAW from Git tags. Using default version \"${MLC_VERSION_RAW}\".")
endif()

string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-([0-9]+)-([a-z0-9]+))?" MLC_VERSION_MATCH ${MLC_VERSION_RAW})
set(MLC_VERSION_MAJOR ${CMAKE_MATCH_1})
set(MLC_VERSION_MINOR ${CMAKE_MATCH_2})
set(MLC_VERSION_PATCH ${CMAKE_MATCH_3})
set(MLC_VERSION_COMMIT_NUM ${CMAKE_MATCH_5})
set(MLC_VERSION_COMMIT_SHA ${CMAKE_MATCH_6})

if (NOT MLC_VERSION_COMMIT_NUM)
set(MLC_VERSION_GIT ${MLC_VERSION_MAJOR}.${MLC_VERSION_MINOR}.${MLC_VERSION_PATCH})
else()
# Increment `MLC_VERSION_PATCH` by 1
math(EXPR MLC_VERSION_PATCH "${MLC_VERSION_PATCH}+1")
set(MLC_VERSION_GIT ${MLC_VERSION_MAJOR}.${MLC_VERSION_MINOR}.${MLC_VERSION_PATCH}.dev${MLC_VERSION_COMMIT_NUM}+${MLC_VERSION_COMMIT_SHA})
endif()
Loading

0 comments on commit 60ec306

Please # to comment.