Skip to content

Store dependency package versions in one place - #2034

Open
slipher wants to merge 3 commits into
DaemonEngine:masterfrom
slipher:deps-versions
Open

slipher wants to merge 3 commits into
DaemonEngine:masterfrom
slipher:deps-versions

Conversation

@slipher

@slipher slipher commented Nov 4, 2026

Copy link
Copy Markdown
Member

When adding support for building the NaCl IRT in build.sh, we will need to know SAIGOSDK_VERSION in a 3rd file, so I decided it's time to store DEPS_VERSION and SAIGOSDK_VERSION constants in a single place. versions.sh can be sourced from shell scripts, or munged into an includable cmake script using cmake's configure_file.

When adding support for building the NaCl IRT in build.sh, we will need
to know SAIGOSDK_VERSION in a 3rd file, so I decided it's time to store
DEPS_VERSION and SAIGOSDK_VERSION constants in a single place.
versions.sh can be sourced from shell scripts, or munged into an
includable cmake script using cmake's configure_file.
@slipher

slipher commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

This could also make it easier to keep testing package builds cleanly separated. Like you could have a temporary commit to use 12-test (rather than immediately using 12) for the package version when testing on the CI.

@illwieckz

illwieckz commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Good idea!

But I think this can be made simpler, for example with that code in CMakeLists.txt:

function(ReadConfigFile CONFIG_FILE)
	file(STRINGS "${CONFIG_FILE}" config_lines)

	# Make sure the list is empty, just in case.
	unset(config_keys)

	foreach(line IN LISTS config_lines)
		# Skip empty lines and comments.
		if (line MATCHES "^[ \t]*#" OR line MATCHES "^[ \t]*$")
			continue()
		endif()

		if (line MATCHES "^([^=]+)=(.*)$")
			set(key "${CMAKE_MATCH_1}")
			set(value "${CMAKE_MATCH_2}")

			# Remove surrounding quotes.
			if (value MATCHES "^\"")
				string(REGEX REPLACE "^\"(.*)\"$" "\\1" value "${value}")
			elseif (value MATCHES "^'")
				string(REGEX REPLACE "^\'(.*)\'$" "\\1" value "${value}")
			endif()

			set("${key}" "${value}")
			list(APPEND config_keys "${key}")
		endif()
	endforeach()

	# Expand variables.
	foreach(key IN LISTS config_keys)
		string(CONFIGURE "${${key}}" expanded_value)
		set("${key}" "${expanded_value}" PARENT_SCOPE)
	endforeach()
endfunction()

# Get DEPS_VERSION, SAIGOSDK_VERSION…
ReadConfigFile("${CMAKE_SOURCE_DIR}/external_deps/versions.conf")

We can then do directly an easy to read and write external_deps/versions.conf that way:

# DEPS_VERSION and SAIGOSDK_VERSION are used to version packages which may be auto-downloaded
# by CMake. The numbers are also included in the install path if you use the scripts to build them
# yourself, so that they end up in the same path used by the download.

# Version for the target-specific library and runtime dependencies package.
# Can be auto-downloaded by CMake or built with build.sh.
DEPS_VERSION=11

# Version for the host mode Saigo NaCl SDK package.
# Can be auto-downloaded by CMake (when building NaCl) or built with sdk-build.sh.
SAIGOSDK_VERSION=20261030

# Only used by sdk-build.sh but it's closely coupled to SAIGOSDK_VERSION.
# Can be a tag like v${SAIGOSDK_VERSION}, or a full commit hash.
SAIGOSDK_REF="v${SAIGOSDK_VERSION}"

And that would be sourced in bash scripts that way:

source "${SCRIPT_DIR}/versions.conf"

And that would not require to write a temporary file.

@slipher

slipher commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

I made a new, totally different version based on the CMake script mode (-P). The file is natively cmake and generates code for the shell to eval if run in script mode. As a general-purpose solution for sharing definitions, one would question making the shell script depend on cmake, but it happens that for our purposes it is unlikely that someone would use these tools without having CMake installed.

@illwieckz

Copy link
Copy Markdown
Member

Yes we can rely on CMake because those build scripts require CMake anyway.
I liked the proposed parser, but that'll do the work.

There is no need for a temporary versions_out and I'm not sure we gain something from it.
If we need to add one line to explain what it does, better do a comment.

eval "$(cmake -P "${SCRIPT_DIR}/versions.cmake" 2>&1)"

@illwieckz

illwieckz commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

You can even add a shebang! 😅️

$ head versions.cmake 
#! /usr/bin/env -S cmake -P
# Daemon BSD Source Code
# Copyright (c) 2026, Daemon Developers
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright
$ chmod +x versions.cmake
$ ./versions.cmake 
DEPS_VERSION='11'
SAIGOSDK_VERSION='20261030'
SAIGOSDK_REF='v20261030'
$ SCRIPT_DIR="$(pwd)"
$ eval "$("${SCRIPT_DIR}/versions.cmake" 2>&1)"
$ echo "${$SAIGOSDK_REF}"
v20261030

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants