Skip to content

Commit

Permalink
Merge branch 'master' into renovate/gh-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Nov 4, 2024
2 parents 23899ae + 563d6d2 commit 441cf5b
Show file tree
Hide file tree
Showing 70 changed files with 1,306 additions and 434 deletions.
162 changes: 162 additions & 0 deletions .github/workflows/mingw-w64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: MinGW-w64 CI

on: [push, pull_request]

permissions: {}

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
steps:
- name: Download Crystal source
uses: actions/checkout@v4

- name: Install LLVM 18
run: |
sudo apt remove 'llvm-*' 'libllvm*'
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
sudo apt-add-repository -y deb http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main
sudo apt install -y llvm-18-dev
- name: Install Crystal
uses: crystal-lang/install-crystal@v1
with:
crystal: "1.14.0"

- name: Cross-compile Crystal
run: make && make -B target=x86_64-windows-gnu release=1 interpreter=1

- name: Upload crystal.obj
uses: actions/upload-artifact@v4
with:
name: x86_64-mingw-w64-crystal-obj
path: .build/crystal.obj

- name: Upload standard library
uses: actions/upload-artifact@v4
with:
name: x86_64-mingw-w64-crystal-stdlib
path: src

x86_64-mingw-w64-link:
runs-on: windows-2022
needs: [x86_64-mingw-w64-cross-compile]
steps:
- name: Setup MSYS2
id: msys2
uses: msys2/setup-msys2@ddf331adaebd714795f1042345e6ca57bd66cea8 # v2.24.1
with:
msystem: UCRT64
update: true
install: >-
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-libffi
- name: Download crystal.obj
uses: actions/download-artifact@v4
with:
name: x86_64-mingw-w64-crystal-obj

- name: Download standard library
uses: actions/download-artifact@v4
with:
name: x86_64-mingw-w64-crystal-stdlib
path: share/crystal/src

- name: Link Crystal executable
shell: msys2 {0}
run: |
mkdir bin
cc crystal.obj -o bin/crystal.exe \
$(pkg-config bdw-gc libpcre2-8 iconv zlib libffi --libs) \
$(llvm-config --libs --system-libs --ldflags) \
-lDbgHelp -lole32 -lWS2_32 -Wl,--stack,0x800000
ldd bin/crystal.exe | grep -iv /c/windows/system32 | sed 's/.* => //; s/ (.*//' | xargs -t -i cp '{}' bin/
- name: Upload Crystal
uses: actions/upload-artifact@v4
with:
name: x86_64-mingw-w64-crystal
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
- name: Run interpreter specs
shell: msys2 {0}
run: |
export PATH="$(pwd)/crystal/bin:$PATH"
export CRYSTAL_SPEC_COMPILER_BIN="$(pwd)/crystal/bin/crystal.exe"
make interpreter_spec
- 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
11 changes: 6 additions & 5 deletions .github/workflows/wasm32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:

jobs:
wasm32-test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
container: crystallang/crystal:1.14.0-build
steps:
- name: Download Crystal source
Expand All @@ -27,10 +27,11 @@ jobs:
- name: Install LLVM
run: |
apt-get update
apt-get install -y curl lsb-release wget software-properties-common gnupg
curl -O https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
./llvm.sh 18
apt-get remove -y 'llvm-*' 'libllvm*'
apt-get install -y curl software-properties-common
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
apt-add-repository -y deb http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main
apt-get install -y llvm-18-dev lld-18
ln -s $(which wasm-ld-18) /usr/bin/wasm-ld
- name: Download wasm32 libs
Expand Down
66 changes: 34 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ 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
stats ?= ## Enable statistics output
progress ?= ## Enable progress output
threads ?= ## Maximum number of threads to use
debug ?= ## Add symbolic debug info
verbose ?= ## Run specs in verbose mode
junit_output ?= ## Path to output junit results
static ?= ## Enable static linking
target ?= ## Cross-compilation target
interpreter ?= ## Enable interpreter feature
check ?= ## Enable only check when running format
order ?=random ## Enable order for spec execution (values: "default" | "random" | seed number)
release ?= ## Compile in release mode
stats ?= ## Enable statistics output
progress ?= ## Enable progress output
threads ?= ## Maximum number of threads to use
debug ?= ## Add symbolic debug info
verbose ?= ## Run specs in verbose mode
junit_output ?= ## Path to output junit results
static ?= ## Enable static linking
target ?= ## Cross-compilation target
interpreter ?= ## Enable interpreter feature
check ?= ## Enable only check when running format
order ?=random ## Enable order for spec execution (values: "default" | "random" | seed number)
deref_symlinks ?= ## Deference symbolic links for `make install`

O := .build
SOURCES := $(shell find src -name '*.cr')
Expand Down Expand Up @@ -68,12 +69,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 +114,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 @@ -166,7 +168,7 @@ install: $(O)/$(CRYSTAL_BIN) man/crystal.1.gz ## Install the compiler at DESTDIR
$(INSTALL) -m 0755 "$(O)/$(CRYSTAL_BIN)" "$(BINDIR)/$(CRYSTAL_BIN)"

$(INSTALL) -d -m 0755 $(DATADIR)
cp -av src "$(DATADIR)/src"
cp $(if $(deref_symlinks),-rvL --preserve=all,-av) src "$(DATADIR)/src"
rm -rf "$(DATADIR)/$(LLVM_EXT_OBJ)" # Don't install llvm_ext.o

$(INSTALL) -d -m 0755 "$(MANDIR)/man1/"
Expand Down Expand Up @@ -212,26 +214,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: 1 addition & 1 deletion bin/crystal
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ esac
if [ -x "$CRYSTAL_DIR/${CRYSTAL_BIN}" ]; then
__warning_msg "Using compiled compiler at ${CRYSTAL_DIR#"$PWD/"}/${CRYSTAL_BIN}"
exec "$CRYSTAL_DIR/${CRYSTAL_BIN}" "$@"
elif !($PARENT_CRYSTAL_EXISTS); then
elif (! $PARENT_CRYSTAL_EXISTS); then
__error_msg 'You need to have a crystal executable in your path! or set CRYSTAL env variable'
exit 1
else
Expand Down
53 changes: 29 additions & 24 deletions spec/compiler/codegen/pointer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -492,28 +492,33 @@ describe "Code gen: pointer" do
)).to_b.should be_true
end

it "takes pointerof lib external var" do
test_c(
%(
int external_var = 0;
),
%(
lib LibFoo
$external_var : Int32
end
LibFoo.external_var = 1
ptr = pointerof(LibFoo.external_var)
x = ptr.value
ptr.value = 10
y = ptr.value
ptr.value = 100
z = LibFoo.external_var
x + y + z
), &.to_i.should eq(111))
end
# FIXME: `$external_var` implies __declspec(dllimport), but we only have an
# object file, so MinGW-w64 fails linking (actually MSVC also emits an
# LNK4217 linker warning)
{% unless flag?(:win32) && flag?(:gnu) %}
it "takes pointerof lib external var" do
test_c(
%(
int external_var = 0;
),
%(
lib LibFoo
$external_var : Int32
end
LibFoo.external_var = 1
ptr = pointerof(LibFoo.external_var)
x = ptr.value
ptr.value = 10
y = ptr.value
ptr.value = 100
z = LibFoo.external_var
x + y + z
), &.to_i.should eq(111))
end
{% end %}
end
2 changes: 1 addition & 1 deletion spec/compiler/codegen/thread_local_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% skip_file if flag?(:openbsd) %}
{% skip_file if flag?(:openbsd) || (flag?(:win32) && flag?(:gnu)) %}

require "../../spec_helper"

Expand Down
Loading

0 comments on commit 441cf5b

Please sign in to comment.