Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix link flag behaviour on Windows MSVC #11424

Merged
merged 1 commit into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Download libpcre
if: steps.cache-libs.outputs.cache-hit != 'true'
run: |
iwr https://ftp.pcre.org/pub/pcre/pcre-8.43.zip -OutFile pcre.zip
iwr https://cs.stanford.edu/pub/exim/pcre/pcre-8.43.zip -OutFile pcre.zip
7z x pcre.zip
mv pcre-* pcre
- name: Build libpcre
Expand Down Expand Up @@ -172,7 +172,7 @@ jobs:

- name: Re-build Crystal
run: |
.\crystal-cross.exe build src/compiler/crystal.cr -Di_know_what_im_doing -Dwithout_playground --link-flags=/F10000000
.\crystal-cross.exe build src/compiler/crystal.cr -Di_know_what_im_doing -Dwithout_playground --link-flags=/STACK:10000000
mv crystal.exe bin/

- name: Gather Crystal binaries
Expand Down
28 changes: 19 additions & 9 deletions src/compiler/crystal/codegen/link.cr
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,27 @@ module Crystal
end

private def lib_flags_windows
String.build do |flags|
link_annotations.reverse_each do |ann|
if ldflags = ann.ldflags
flags << ' ' << ldflags
end

if libname = ann.lib
flags << ' ' << Process.quote_windows("#{libname}.lib")
end
flags = [] of String

# Add CRYSTAL_LIBRARY_PATH locations, so the linker preferentially
# searches user-given library paths.
if has_flag?("msvc")
CrystalLibraryPath.paths.each do |path|
flags << Process.quote_windows("/LIBPATH:#{path}")
end
end

link_annotations.reverse_each do |ann|
if ldflags = ann.ldflags
flags << ldflags
end

if libname = ann.lib
flags << Process.quote_windows("#{libname}.lib")
end
end

flags.join(" ")
end

private def lib_flags_posix
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,15 @@ module Crystal
end

private def linker_command(program : Program, object_names, output_filename, output_dir, expand = false)
if program.has_flag? "windows"
if program.has_flag? "msvc"
lib_flags = program.lib_flags
# Execute and expand `subcommands`.
lib_flags = lib_flags.gsub(/`(.*?)`/) { `#{$1}` } if expand

object_arg = Process.quote_windows(object_names)
output_arg = Process.quote_windows("/Fe#{output_filename}")

args = %(/nologo #{object_arg} #{output_arg} #{lib_flags} #{@link_flags})
args = %(/nologo #{object_arg} #{output_arg} /link #{lib_flags} #{@link_flags}).gsub("\n", " ")
cmd = "#{CL} #{args}"

if cmd.to_utf16.size > 32000
Expand Down