Skip to content

Commit

Permalink
Add more customizations to Crystal::Config.description
Browse files Browse the repository at this point in the history
* Allow passing in git sha and date to Makefile
* Remove empty parens when date is ""
* Add message when compiler was not compiled in release mode

When building in a nix derivation, there is no git directory, so you
have to pass in the sha manually. Also, all the file modification
times are set to epcoh, and I think it'd be nicer to just have the
builds not have a date rather than the obviously wrong 1970-01-01.

I don't think we need to always have release mode information, but it
would be useful I think to have a way to see when you're working with a
non-release compiler.
  • Loading branch information
will committed Mar 31, 2023
1 parent b31b07d commit cafec08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ override FLAGS += -D strict_multi_assign -D preview_overload_order $(if $(releas
SPEC_WARNINGS_OFF := --exclude-warnings spec/std --exclude-warnings spec/compiler --exclude-warnings spec/primitives
SPEC_FLAGS := $(if $(verbose),-v )$(if $(junit_output),--junit_output $(junit_output) )$(if $(order),--order=$(order) )
CRYSTAL_CONFIG_LIBRARY_PATH := '$$ORIGIN/../lib/crystal'
CRYSTAL_CONFIG_BUILD_COMMIT := $(shell git rev-parse --short HEAD 2> /dev/null)
CRYSTAL_CONFIG_BUILD_COMMIT ?= $(shell git rev-parse --short HEAD 2> /dev/null)
CRYSTAL_CONFIG_PATH := '$$ORIGIN/../share/crystal/src'
SOURCE_DATE_EPOCH := $(shell (git show -s --format=%ct HEAD || stat -c "%Y" Makefile || stat -f "%m" Makefile) 2> /dev/null)
SOURCE_DATE_EPOCH ?= $(shell (git show -s --format=%ct HEAD || stat -c "%Y" Makefile || stat -f "%m" Makefile) 2> /dev/null)
ifeq ($(shell command -v ld.lld >/dev/null && uname -s),Linux)
EXPORT_CC ?= CC="$(CC) -fuse-ld=lld"
endif
Expand Down
15 changes: 13 additions & 2 deletions src/compiler/crystal/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ module Crystal

def self.description
formatted_sha = "[#{build_commit}] " if build_commit
formatted_date = "(#{date})" unless date.empty?
release_msg = "\nRelease mode: false" unless release_mode

<<-DOC
Crystal #{version} #{formatted_sha}(#{date})
Crystal #{version} #{formatted_sha}#{formatted_date}
LLVM: #{llvm_version}
Default target: #{self.host_target}
Default target: #{self.host_target}#{release_msg}
DOC
end

Expand All @@ -40,6 +43,14 @@ module Crystal
end
end

def self.release_mode
{% if flag?(:release) %}
true
{% else %}
false
{% end %}
end

@@host_target : Crystal::Codegen::Target?

def self.host_target : Crystal::Codegen::Target
Expand Down

0 comments on commit cafec08

Please sign in to comment.