Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a basic implementation for the Zig port with proper testings #478

Merged
merged 7 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions cmake/FindZig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# CMake Find Zig by Parra Studios
# CMake script to find Zig compiler and tools.
#
# Copyright (C) 2016 - 2024 Vicente Eduardo Ferrer Garcia <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Find Zig executables and paths
#
# Zig_FOUND - True if Zig was found
# Zig_COMPILER_EXECUTABLE - Zig compiler executable path

# Options
#
# Zig_CMAKE_DEBUG - Print the debug information and all constants values

option(Zig_CMAKE_DEBUG "Show full output of the Zig related commands for debugging." OFF)

find_program(Zig_COMPILER_EXECUTABLE zig
)

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(Zig
FOUND_VAR Zig_FOUND
)

mark_as_advanced(
Zig_FOUND
Zig_COMPILER_EXECUTABLE
)

if(Zig_CMAKE_DEBUG)
message(STATUS "Zig_COMPILER_EXECUTABLE: ${Zig_COMPILER_EXECUTABLE}")
endif()
2 changes: 2 additions & 0 deletions source/ports/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ option(OPTION_BUILD_PORTS_R "Build R port." OFF)
option(OPTION_BUILD_PORTS_RB "Build Ruby port." ON)
option(OPTION_BUILD_PORTS_RS "Build Rust port." OFF)
option(OPTION_BUILD_PORTS_TS "Build TypeScript port." OFF)
option(OPTION_BUILD_PORTS_ZIG "Build Zig port." OFF)

#
# Port languages (Standalone)
Expand All @@ -52,6 +53,7 @@ add_subdirectory(node_port)
add_subdirectory(py_port)
add_subdirectory(go_port)
add_subdirectory(rs_port)
add_subdirectory(zig_port)

#
# External dependencies
Expand Down
6 changes: 6 additions & 0 deletions source/ports/zig_port/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Zig cache and binary directories
zig-cache
zig-out

# Python loader cache in testings
src/tests/__pycache__
47 changes: 47 additions & 0 deletions source/ports/zig_port/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Check if this port is enabled
if(NOT OPTION_BUILD_PORTS OR NOT OPTION_BUILD_PORTS_ZIG)
return()
endif()

#
# Port name and options
#

find_package(Zig)

if(NOT Zig_FOUND)
message(SEND_ERROR "Zig not found")
return()
endif()

# Target name
set(target zig_port)

# Exit here if required dependencies are not met
message(STATUS "Port ${target}")

# Generate bindings
add_custom_target(TARGET ${target}
COMMAND ${Zig_COMPILER_EXECUTABLE} translate-c metacall.h > metacall-bindings.zig -lc -I ${CMAKE_SOURCE_DIR}/source/metacall/include -I ${CMAKE_BINARY_DIR}/source/metacall/include -I ${CMAKE_BINARY_DIR}/source/include
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

#
# Define test
#

add_test(NAME ${target}
COMMAND ${Zig_COMPILER_EXECUTABLE} build test
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

set_property(TEST ${target}
PROPERTY LABELS ${target}
)

include(TestEnvironmentVariables)

test_environment_variables(${target}
""
${TESTS_ENVIRONMENT_VARIABLES}
)
18 changes: 0 additions & 18 deletions source/ports/zig_port/metacall.zig

This file was deleted.

Loading
Loading