diff --git a/.github/workflows/mingw-w64-steps.yml b/.github/workflows/mingw-w64-steps.yml index c1eea06e5a6e..ca9dbd25392b 100644 --- a/.github/workflows/mingw-w64-steps.yml +++ b/.github/workflows/mingw-w64-steps.yml @@ -146,20 +146,17 @@ jobs: - name: Run compiler specs shell: msys2 {0} run: | - export CRYSTAL_SPEC_COMPILER_BIN="$(which crystal.exe)" - make compiler_spec + make compiler_spec CRYSTAL=.build/crystal - name: Run interpreter specs shell: msys2 {0} run: | - export CRYSTAL_SPEC_COMPILER_BIN="$(which crystal.exe)" - make interpreter_spec + make interpreter_spec CRYSTAL=.build/crystal - name: Run primitives specs shell: msys2 {0} run: | - export CRYSTAL_SPEC_COMPILER_BIN="$(which crystal.exe)" - make -o .build/crystal.exe primitives_spec # we know the compiler is fresh; do not rebuild it here + make -o .build/crystal.exe primitives_spec CRYSTAL=.build/crystal.exe # we know the compiler is fresh; do not rebuild it here env: SPEC_FLAGS: --tag=~external_commands # skip exec_external_command spec because it doesn't work with this setup diff --git a/.github/workflows/win.yml b/.github/workflows/win.yml index 7f4f40adc6a6..5474f0850beb 100644 --- a/.github/workflows/win.yml +++ b/.github/workflows/win.yml @@ -240,7 +240,7 @@ jobs: - name: Set up environment run: | - Add-Content $env:GITHUB_PATH "$(pwd)\build" + Add-Content $env:GITHUB_ENV "CRYSTAL=$(pwd)\build\crystal.exe" Add-Content $env:GITHUB_ENV "CRYSTAL_SPEC_COMPILER_BIN=$(pwd)\build\crystal.exe" Add-Content $env:GITHUB_ENV "LLVM_VERSION=${{ env.CI_LLVM_VERSION }}" Add-Content $env:GITHUB_ENV "LLVM_TARGETS=${{ env.CI_LLVM_TARGETS }}" @@ -262,7 +262,7 @@ jobs: run: make -f Makefile.win cli_spec - name: Build samples - run: make -f Makefile.win samples + run: make -f Makefile.win -C samples test-std: runs-on: windows-2025-vs2026 @@ -295,8 +295,7 @@ jobs: - name: Set up environment run: | - Add-Content $env:GITHUB_PATH "$(pwd)\build" - Add-Content $env:GITHUB_ENV "CRYSTAL_SPEC_COMPILER_BIN=$(pwd)\build\crystal.exe" + Add-Content $env:GITHUB_ENV "CRYSTAL=$(pwd)\build\crystal.exe" Add-Content $env:GITHUB_ENV "LLVM_VERSION=${{ env.CI_LLVM_VERSION }}" Add-Content $env:GITHUB_ENV "LLVM_TARGETS=${{ env.CI_LLVM_TARGETS }}" Add-Content $env:GITHUB_ENV "LLVM_LDFLAGS=${{ env.CI_LLVM_LDFLAGS }}" @@ -327,8 +326,7 @@ jobs: - name: Set up environment run: | - Add-Content $env:GITHUB_PATH "$(pwd)\build" - Add-Content $env:GITHUB_ENV "CRYSTAL_SPEC_COMPILER_BIN=$(pwd)\build\crystal.exe" + Add-Content $env:GITHUB_ENV "CRYSTAL=$(pwd)\build\crystal.exe" Add-Content $env:GITHUB_ENV "LLVM_VERSION=${{ env.CI_LLVM_VERSION }}" Add-Content $env:GITHUB_ENV "LLVM_TARGETS=${{ env.CI_LLVM_TARGETS }}" Add-Content $env:GITHUB_ENV "LLVM_LDFLAGS=${{ env.CI_LLVM_LDFLAGS }}" diff --git a/Makefile b/Makefile index c3bebf6ec3b1..e2beb3440667 100644 --- a/Makefile +++ b/Makefile @@ -285,7 +285,7 @@ $(O)/compiler_spec$(EXE): $(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 + $(EXPORT_CC) ./$(O)/crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o $@ spec/primitives_spec.cr $(O)/cli_spec$(EXE): $(O)/$(CRYSTAL_BIN) $(DEPS) $(SOURCES) $(SPEC_SOURCES) @mkdir -p $(O) diff --git a/Makefile.win b/Makefile.win index bece8f7cc555..9c40fbd5da3c 100644 --- a/Makefile.win +++ b/Makefile.win @@ -223,7 +223,7 @@ $(O)\compiler_spec.exe: $(DEPS) $(SOURCES) $(SPEC_SOURCES) $(O)\primitives_spec.exe: $(O)\crystal.exe $(DEPS) $(SOURCES) $(SPEC_SOURCES) @$(call MKDIR,"$(O)") - .\bin\crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o "$@" spec\primitives_spec.cr + $(O)\crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o "$@" spec\primitives_spec.cr $(O)\cli_spec.exe: $(O)\crystal.exe $(DEPS) $(SOURCES) $(SPEC_SOURCES) @$(call MKDIR,"$(O)") diff --git a/bin/ci b/bin/ci index 81426831ac94..35853022ceeb 100755 --- a/bin/ci +++ b/bin/ci @@ -106,28 +106,29 @@ build() { case $ARCH in i386) with_build_env 'make crystal threads=1' - with_build_env 'SPEC_SPLIT="0%4" make std_spec threads=1 junit_output=.junit/std_spec.0.xml' - with_build_env 'SPEC_SPLIT="1%4" make std_spec threads=1 junit_output=.junit/std_spec.1.xml' - with_build_env 'SPEC_SPLIT="2%4" make std_spec threads=1 junit_output=.junit/std_spec.2.xml' - with_build_env 'SPEC_SPLIT="3%4" make std_spec threads=1 junit_output=.junit/std_spec.3.xml' + with_build_env 'SPEC_SPLIT="0%4" make CRYSTAL=.build/crystal std_spec threads=1 junit_output=.junit/std_spec.0.xml' + with_build_env 'SPEC_SPLIT="1%4" make CRYSTAL=.build/crystal std_spec threads=1 junit_output=.junit/std_spec.1.xml' + with_build_env 'SPEC_SPLIT="2%4" make CRYSTAL=.build/crystal std_spec threads=1 junit_output=.junit/std_spec.2.xml' + with_build_env 'SPEC_SPLIT="3%4" make CRYSTAL=.build/crystal std_spec threads=1 junit_output=.junit/std_spec.3.xml' parts=16 i=0 while [ $i -lt $parts ]; do - with_build_env "CRYSTAL_SPEC_COMPILER_THREADS=1 SPEC_SPLIT=\"$i%$parts\" make compiler_spec threads=1 junit_output=.junit/compiler_spec.$i.xml" + with_build_env "CRYSTAL_SPEC_COMPILER_THREADS=1 SPEC_SPLIT=\"$i%$parts\" make CRYSTAL=.build/crystal compiler_spec threads=1 junit_output=.junit/compiler_spec.$i.xml" i=$((i + 1)) done - with_build_env 'make primitives_spec threads=1 junit_output=.junit/primitives_spec.xml' - with_build_env 'make docs threads=1' + with_build_env 'make CRYSTAL=.build/crystal primitives_spec threads=1 junit_output=.junit/primitives_spec.xml' + with_build_env 'make CRYSTAL=.build/crystal docs threads=1' ;; *) - with_build_env 'make crystal primitives_spec std_spec compiler_spec docs threads=1 junit_output=.junit/spec.xml DOCS_OPTIONS="--json-config-url=/api/versions.json --canonical-base-url=https://crystal-lang.org/api/latest/"' + with_build_env 'make crystal' + with_build_env 'make CRYSTAL=.build/crystal primitives_spec std_spec compiler_spec docs threads=1 junit_output=.junit/spec.xml DOCS_OPTIONS="--json-config-url=/api/versions.json --canonical-base-url=https://crystal-lang.org/api/latest/"' ;; esac - with_build_env 'make samples' - with_build_env 'CRYSTAL_OPTS=--debug make samples' + with_build_env 'make -C samples CRYSTAL=../.build/crystal' + with_build_env 'CRYSTAL_OPTS=--debug make -C samples CRYSTAL=../.build/crystal' } format() { diff --git a/bin/crystal b/bin/crystal index 98d0903fdd0b..2dc229c1efc2 100755 --- a/bin/crystal +++ b/bin/crystal @@ -185,11 +185,6 @@ case "$(uname -s)" in ;; esac -# CRYSTAL_EXEC_PATH determines the location of the `crystal` program for external -# compiler commands. -CRYSTAL_EXEC_PATH="$SCRIPT_ROOT" -export CRYSTAL_EXEC_PATH - if [ -x "$CRYSTAL_DIR/${CRYSTAL_BIN}" ]; then __warning_msg "Using compiled compiler at ${CRYSTAL_DIR#"$PWD/"}/${CRYSTAL_BIN}" exec "$CRYSTAL_DIR/${CRYSTAL_BIN}" "$@" @@ -197,5 +192,10 @@ 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 + # CRYSTAL_EXEC_PATH determines the location of the `crystal` program for external + # compiler commands. + CRYSTAL_EXEC_PATH="$SCRIPT_ROOT" + export CRYSTAL_EXEC_PATH + exec "$PARENT_CRYSTAL" "$@" fi diff --git a/spec/manual/find_executable_spec.cr b/spec/manual/find_executable_spec.cr index 01bfd12f4d88..816e4c613df4 100644 --- a/spec/manual/find_executable_spec.cr +++ b/spec/manual/find_executable_spec.cr @@ -23,7 +23,7 @@ describe "Process.run" do src_fn = test_dir / "self_printer.cr" exe_fn = test_dir / "self_printer.exe" File.write(src_fn, "print #{name.inspect}") - Process.run(ENV["CRYSTAL_SPEC_COMPILER_BIN"]? || "bin/crystal", ["build", "-o", exe_fn.to_s, src_fn.to_s]) + Process.run(ENV["CRYSTAL_SPEC_COMPILER_BIN"]? || File.join(".build", "crystal"), ["build", "-o", exe_fn.to_s, src_fn.to_s]) Dir.mkdir_p((base_dir / name).parent) File.rename(exe_fn, base_dir / name) end diff --git a/src/compiler/crystal/crystal_path.cr b/src/compiler/crystal/crystal_path.cr index 2e10c9e567f8..f1a5e1ab050f 100644 --- a/src/compiler/crystal/crystal_path.cr +++ b/src/compiler/crystal/crystal_path.cr @@ -21,6 +21,8 @@ module Crystal def self.default_paths : Array(String) if path = ENV["CRYSTAL_PATH"]? path_array = path.split(Process::PATH_DELIMITER, remove_empty: true) + elsif dev_path = dev_path? + path_array = [DEFAULT_LIB_PATH, dev_path] elsif path = Crystal::Config.path.presence path_array = path.split(Process::PATH_DELIMITER, remove_empty: true) unless path_array.includes?(DEFAULT_LIB_PATH) @@ -35,6 +37,16 @@ module Crystal path_array end + def self.dev_path? : String? + exe_path = Process.executable_path || return + dir_path = ::Path[exe_path].parent + return unless dir_path.basename == ".build" + + src_path = dir_path.parent.join("src").to_s + return unless Dir.exists?(src_path) + src_path + end + def self.default_path : String default_paths.join(Process::PATH_DELIMITER) end