Skip to content

Commit

Permalink
Merge branch 'master' into feature/indirect-branch-tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Oct 29, 2024
2 parents 0ea07f6 + 6118fa2 commit 8b804dc
Show file tree
Hide file tree
Showing 30 changed files with 589 additions and 226 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/mingw-w64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

env:
SPEC_SPLIT_DOTS: 160

jobs:
x86_64-mingw-w64-cross-compile:
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -89,3 +92,63 @@ jobs:
path: |
bin/
share/
x86_64-mingw-w64-test:
runs-on: windows-2022
needs: [x86_64-mingw-w64-link]
steps:
- name: Setup MSYS2
id: msys2
uses: msys2/setup-msys2@ddf331adaebd714795f1042345e6ca57bd66cea8 # v2.24.1
with:
msystem: UCRT64
update: true
install: >-
git
make
mingw-w64-ucrt-x86_64-pkgconf
mingw-w64-ucrt-x86_64-cc
mingw-w64-ucrt-x86_64-gc
mingw-w64-ucrt-x86_64-pcre2
mingw-w64-ucrt-x86_64-libiconv
mingw-w64-ucrt-x86_64-zlib
mingw-w64-ucrt-x86_64-llvm
mingw-w64-ucrt-x86_64-gmp
mingw-w64-ucrt-x86_64-libxml2
mingw-w64-ucrt-x86_64-libyaml
mingw-w64-ucrt-x86_64-openssl
mingw-w64-ucrt-x86_64-libffi
- name: Disable CRLF line ending substitution
run: |
git config --global core.autocrlf false
- name: Download Crystal source
uses: actions/checkout@v4

- name: Download Crystal executable
uses: actions/download-artifact@v4
with:
name: x86_64-mingw-w64-crystal
path: crystal

- name: Run stdlib specs
shell: msys2 {0}
run: |
export PATH="$(pwd)/crystal/bin:$PATH"
export CRYSTAL_SPEC_COMPILER_BIN="$(pwd)/crystal/bin/crystal.exe"
make std_spec
- name: Run compiler specs
shell: msys2 {0}
run: |
export PATH="$(pwd)/crystal/bin:$PATH"
export CRYSTAL_SPEC_COMPILER_BIN="$(pwd)/crystal/bin/crystal.exe"
make compiler_spec FLAGS=-Dwithout_ffi
- name: Run primitives specs
shell: msys2 {0}
run: |
export PATH="$(pwd)/crystal/bin:$PATH"
export CRYSTAL_SPEC_COMPILER_BIN="$(pwd)/crystal/bin/crystal.exe"
make -o .build/crystal.exe primitives_spec # we know the compiler is fresh; do not rebuild it here
39 changes: 20 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ all:
## Run generators (Unicode, SSL config, ...)
## $ make -B generate_data

CRYSTAL ?= crystal ## which previous crystal compiler use
CRYSTAL ?= crystal## which previous crystal compiler use
LLVM_CONFIG ?= ## llvm-config command path to use

release ?= ## Compile in release mode
Expand Down Expand Up @@ -68,12 +68,13 @@ CXXFLAGS += $(if $(debug),-g -O0)

# MSYS2 support (native Windows should use `Makefile.win` instead)
ifeq ($(OS),Windows_NT)
CRYSTAL_BIN := crystal.exe
EXE := .exe
WINDOWS := 1
else
CRYSTAL_BIN := crystal
EXE :=
WINDOWS :=
endif
CRYSTAL_BIN := crystal$(EXE)

DESTDIR ?=
PREFIX ?= /usr/local
Expand Down Expand Up @@ -112,28 +113,28 @@ test: spec ## Run tests
spec: std_spec primitives_spec compiler_spec

.PHONY: std_spec
std_spec: $(O)/std_spec ## Run standard library specs
$(O)/std_spec $(SPEC_FLAGS)
std_spec: $(O)/std_spec$(EXE) ## Run standard library specs
$(O)/std_spec$(EXE) $(SPEC_FLAGS)

.PHONY: compiler_spec
compiler_spec: $(O)/compiler_spec ## Run compiler specs
$(O)/compiler_spec $(SPEC_FLAGS)
compiler_spec: $(O)/compiler_spec$(EXE) ## Run compiler specs
$(O)/compiler_spec$(EXE) $(SPEC_FLAGS)

.PHONY: primitives_spec
primitives_spec: $(O)/primitives_spec ## Run primitives specs
$(O)/primitives_spec $(SPEC_FLAGS)
primitives_spec: $(O)/primitives_spec$(EXE) ## Run primitives specs
$(O)/primitives_spec$(EXE) $(SPEC_FLAGS)

.PHONY: interpreter_spec
interpreter_spec: $(O)/interpreter_spec ## Run interpreter specs
$(O)/interpreter_spec $(SPEC_FLAGS)
interpreter_spec: $(O)/interpreter_spec$(EXE) ## Run interpreter specs
$(O)/interpreter_spec$(EXE) $(SPEC_FLAGS)

.PHONY: smoke_test
smoke_test: ## Build specs as a smoke test
smoke_test: $(O)/std_spec $(O)/compiler_spec $(O)/$(CRYSTAL_BIN)
smoke_test: $(O)/std_spec$(EXE) $(O)/compiler_spec$(EXE) $(O)/$(CRYSTAL_BIN)

.PHONY: all_spec
all_spec: $(O)/all_spec ## Run all specs (note: this builds a huge program; `test` recipe builds individual binaries and is recommended for reduced resource usage)
$(O)/all_spec $(SPEC_FLAGS)
all_spec: $(O)/all_spec$(EXE) ## Run all specs (note: this builds a huge program; `test` recipe builds individual binaries and is recommended for reduced resource usage)
$(O)/all_spec$(EXE) $(SPEC_FLAGS)

.PHONY: samples
samples: ## Build example programs
Expand Down Expand Up @@ -212,26 +213,26 @@ uninstall_docs: ## Uninstall docs from DESTDIR
rm -rf "$(DATADIR)/docs"
rm -rf "$(DATADIR)/examples"

$(O)/all_spec: $(DEPS) $(SOURCES) $(SPEC_SOURCES)
$(O)/all_spec$(EXE): $(DEPS) $(SOURCES) $(SPEC_SOURCES)
$(call check_llvm_config)
@mkdir -p $(O)
$(EXPORT_CC) $(EXPORTS) ./bin/crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o $@ spec/all_spec.cr

$(O)/std_spec: $(DEPS) $(SOURCES) $(SPEC_SOURCES)
$(O)/std_spec$(EXE): $(DEPS) $(SOURCES) $(SPEC_SOURCES)
$(call check_llvm_config)
@mkdir -p $(O)
$(EXPORT_CC) ./bin/crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o $@ spec/std_spec.cr

$(O)/compiler_spec: $(DEPS) $(SOURCES) $(SPEC_SOURCES)
$(O)/compiler_spec$(EXE): $(DEPS) $(SOURCES) $(SPEC_SOURCES)
$(call check_llvm_config)
@mkdir -p $(O)
$(EXPORT_CC) $(EXPORTS) ./bin/crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o $@ spec/compiler_spec.cr --release

$(O)/primitives_spec: $(O)/$(CRYSTAL_BIN) $(DEPS) $(SOURCES) $(SPEC_SOURCES)
$(O)/primitives_spec$(EXE): $(O)/$(CRYSTAL_BIN) $(DEPS) $(SOURCES) $(SPEC_SOURCES)
@mkdir -p $(O)
$(EXPORT_CC) ./bin/crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o $@ spec/primitives_spec.cr

$(O)/interpreter_spec: $(DEPS) $(SOURCES) $(SPEC_SOURCES)
$(O)/interpreter_spec$(EXE): $(DEPS) $(SOURCES) $(SPEC_SOURCES)
$(eval interpreter=1)
@mkdir -p $(O)
$(EXPORT_CC) ./bin/crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o $@ spec/compiler/interpreter_spec.cr
Expand Down
2 changes: 2 additions & 0 deletions spec/compiler/crystal/tools/doc/project_info_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ private alias ProjectInfo = Crystal::Doc::ProjectInfo

private def run_git(command)
Process.run(%(git -c user.email="" -c user.name="spec" #{command}), shell: true)
rescue IO::Error
pending! "Git is not available"
end

private def assert_with_defaults(initial, expected, *, file = __FILE__, line = __LINE__)
Expand Down
14 changes: 12 additions & 2 deletions spec/compiler/crystal/tools/init_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ private def run_init_project(skeleton_type, name, author, email, github_name, di
).run
end

private def git_available?
Process.run(Crystal::Git.executable).success?
rescue IO::Error
false
end

module Crystal
describe Init::InitProject do
it "correctly uses git config" do
pending! "Git is not available" unless git_available?

within_temporary_directory do
File.write(".gitconfig", <<-INI)
[user]
Expand Down Expand Up @@ -212,9 +220,11 @@ module Crystal
)
end

with_file "example/.git/config" { }
if git_available?
with_file "example/.git/config" { }

with_file "other-example-directory/.git/config" { }
with_file "other-example-directory/.git/config" { }
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/loader/unix_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe Crystal::Loader do
with_env "LD_LIBRARY_PATH": "ld1::ld2", "DYLD_LIBRARY_PATH": nil do
search_paths = Crystal::Loader.default_search_paths
{% if flag?(:darwin) %}
search_paths.should eq ["/usr/lib", "/usr/local/lib"]
search_paths[-2..].should eq ["/usr/lib", "/usr/local/lib"]
{% else %}
search_paths[0, 2].should eq ["ld1", "ld2"]
{% if flag?(:android) %}
Expand Down
6 changes: 3 additions & 3 deletions spec/std/exception/call_stack_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ describe "Backtrace" do

_, output, _ = compile_and_run_file(source_file)

# resolved file:line:column (no column for windows PDB because of poor
# support in general)
{% if flag?(:win32) %}
# resolved file:line:column (no column for MSVC PDB because of poor support
# by external tooling in general)
{% if flag?(:msvc) %}
output.should match(/^#{Regex.escape(source_file)}:3 in 'callee1'/m)
output.should match(/^#{Regex.escape(source_file)}:13 in 'callee3'/m)
{% else %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/aarch64_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::AArch64
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:aarch64) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/arm_abi_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::ARM
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:arm) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/avr_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::AVR
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:avr) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/llvm_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM
{% skip_file %}
{% end %}

require "llvm"

describe LLVM do
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/type_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::Type
{% skip_file %}
{% end %}

require "llvm"

describe LLVM::Type do
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/x86_64_abi_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::X86_64
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/x86_abi_spec.cr
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
{% skip_file if flag?(:win32) %} # 32-bit windows is not supported

require "spec"

{% if flag?(:interpreted) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::X86
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ module Crystal
link_flags += " -Wl,--stack,0x800000"
lib_flags = program.lib_flags(@cross_compile)
lib_flags = expand_lib_flags(lib_flags) if expand
cmd = %(#{DEFAULT_LINKER} #{Process.quote_windows(object_names)} -o #{Process.quote_windows(output_filename)} #{link_flags} #{lib_flags})
cmd = %(#{DEFAULT_LINKER} #{Process.quote_windows(object_names)} -o #{Process.quote_windows(output_filename)} #{link_flags} #{lib_flags}).gsub('\n', ' ')

if cmd.size > 32000
# The command line would be too big, pass the args through a file instead.
Expand Down Expand Up @@ -507,7 +507,6 @@ module Crystal
link_flags += " -L/usr/local/lib"
end


{DEFAULT_LINKER, %(#{DEFAULT_LINKER} "${@}" -o #{Process.quote_posix(output_filename)} #{link_flags} #{program.lib_flags(@cross_compile)}), object_names}
end
end
Expand Down
31 changes: 30 additions & 1 deletion src/compiler/crystal/loader/unix.cr
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ class Crystal::Loader
parser.unknown_args do |args, after_dash|
file_paths.concat args
end

# although flags starting with `-Wl,` appear in `args` above, this is
# still called by `OptionParser`, so we assume it is fine to ignore these
# flags
parser.invalid_option do |arg|
unless arg.starts_with?("-Wl,")
raise LoadError.new "Not a recognized linker flag: #{arg}"
end
end
end

search_paths = extra_search_paths + search_paths
Expand Down Expand Up @@ -162,6 +171,10 @@ class Crystal::Loader
read_ld_conf(default_search_paths)
{% end %}

cc_each_library_path do |path|
default_search_paths << path
end

{% if flag?(:darwin) %}
default_search_paths << "/usr/lib"
default_search_paths << "/usr/local/lib"
Expand All @@ -179,7 +192,7 @@ class Crystal::Loader
default_search_paths << "/usr/lib"
{% end %}

default_search_paths
default_search_paths.uniq!
end

def self.read_ld_conf(array = [] of String, path = "/etc/ld.so.conf") : Nil
Expand All @@ -201,4 +214,20 @@ class Crystal::Loader
end
end
end

def self.cc_each_library_path(& : String ->) : Nil
search_dirs = begin
`#{Crystal::Compiler::DEFAULT_LINKER} -print-search-dirs`
rescue IO::Error
return
end

search_dirs.each_line do |line|
if libraries = line.lchop?("libraries: =")
libraries.split(Process::PATH_DELIMITER) do |path|
yield File.expand_path(path)
end
end
end
end
end
Loading

0 comments on commit 8b804dc

Please sign in to comment.