Skip to content

Invidious is an alternative front-end to YouTube

feat: show message for unsupported Crystal versions at compile time (#5909)

Fijxub052ced0b4be
diff --git a/Makefile b/Makefile
index 96599dc1..f7f01527 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,7 @@ RELEASE := 1
STATIC := 0
NO_DBG_SYMBOLS := 0
+SKIP_VERSION_CHECK := 0
FLAGS ?=
@@ -27,6 +28,9 @@ ifeq ($(API_ONLY), 1)
FLAGS += -Dapi_only
endif
+ifeq ($(SKIP_VERSION_CHECK), 1)
+ FLAGS += -Dskip_version_check
+endif
# -----------------------
# Main
@@ -103,11 +107,12 @@ help:
@echo ""
@echo "Build options available for this Makefile:"
@echo ""
- @echo " RELEASE Make a release build (Default: 1)"
- @echo " STATIC Link libraries statically (Default: 0)"
+ @echo " RELEASE Make a release build (Default: 1)"
+ @echo " STATIC Link libraries statically (Default: 0)"
@echo ""
- @echo " API_ONLY Build invidious without a GUI (Default: 0)"
- @echo " NO_DBG_SYMBOLS Strip debug symbols (Default: 0)"
+ @echo " API_ONLY Build invidious without a GUI (Default: 0)"
+ @echo " NO_DBG_SYMBOLS Strip debug symbols (Default: 0)"
+ @echo " SKIP_VERSION_CHECK Skips the Crystal compiler version check (Default: 0)"
diff --git a/shard.yml b/shard.yml
index 779a2569..0e62f6f6 100644
--- a/shard.yml
+++ b/shard.yml
@@ -10,7 +10,7 @@ targets:
main: src/invidious.cr
description: |
- Invidious is an alternative front-end to YouTube
+ Invidious is an alternative front-end to YouTube
dependencies:
pg:
@@ -40,7 +40,7 @@ development_dependencies:
github: crystal-ameba/ameba
version: ~> 1.6.1
-crystal: ">= 1.10.0, < 2.0.0"
+crystal: ">= 1.14.1, < 2.0.0"
license: AGPL-3.0-only
diff --git a/src/invidious.cr b/src/invidious.cr
index 09fbb624..cc65dde0 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -50,6 +50,27 @@ require "./invidious/routes/**"
require "./invidious/jobs/base_job"
require "./invidious/jobs/*"
+# Show a nice message in case the current Crystal compiler version is unsupoported```
+# encouraging the user compiling Invidious to update it```
+# version.
+{% begin %}
+ # `-Dskip_version_check` compile-time flag, for development purposes
+ # or weird installations that lack the `shard.yml` file when compiling
+ # Invidious.
+ {% if !flag?(:skip_version_check) %}
+ {% if file_exists?("#{__DIR__}/../shard.yml") %}
+ {% shard_yml = read_file("#{__DIR__}/../shard.yml") %}
+ {% crystal_constraint = shard_yml.split('\n').find(&.starts_with?("crystal:")) %}
+ {% minimum_version = crystal_constraint.split('"')[1].split(",").first.split(">=").last.strip %}
+ {% if compare_versions(Crystal::VERSION, minimum_version) < 0 %}
+ {{ raise "Crystal version #{minimum_version} or newer is required to build Invidious. \
+ You currently have Crystal version #{Crystal::VERSION} installed. \
+ We recommend that you install it following the way that the team behind the Crystal compiler itself recommend for your OS, see: https://crystal-lang.org/install/" }}
+ {% end %}
+ {% end %}
+ {% end %}
+{% end %}
+
# Declare the base namespace for invidious
module Invidious
end