odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.89k stars 606 forks source link

odin CLI ignores escaped quotes inside -extra-linker-flags argument on Windows #2741

Open lem0nify opened 1 year ago

lem0nify commented 1 year ago

Context

Odin: dev-2023-08-nightly:49b24471 OS: Windows 10 Home Basic (version: 22H2), build 19045.3324 CPU: Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz RAM: 4095 MiB

Expected Behavior

I expect the possibility to provide additional library search path which contains spaces to the link.exe linker on Windows (with command line, not environment variable)

Current Behavior

odin CLI tool ignores escaped quotes in -extra-linker-flags argument additionally, if I pass not only /LIBPATH:"..." argument but at least one more single-word argument before it, odin passes quoted string to the linker truncated at the first space for some reason

Failure Information (for bugs)

PS C:\Users\lem0nify\code\odin\example> odin build . -show-system-calls -extra-linker-flags:"/LIBPATH:""C:\Users\lem0nify\code\odin\path with spaces"""
[SYSTEM CALL] msvc-link
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/link.exe" "C:/Users/lem0nify/code/odin/example/example.obj"   -OUT:"C:/Users/lem0nify/code/odin/example/example.exe"  /LIBPATH:"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64" /LIBPATH:"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/ucrt/x64" /LIBPATH:"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/lib/x64" /ENTRY:mainCRTStartup /defaultlib:libcmt /NOIMPLIB /NOEXP /nologo /incremental:no /opt:ref /subsystem:CONSOLE /machine:x64  /LIBPATH:C:\Users\lem0nify\code\odin\path with spaces  "kernel32.lib" "foo.lib"

LINK : fatal error LNK1181: cannot open input file 'with.obj'

PS C:\Users\lem0nify\code\odin\example> odin build . -show-system-calls -extra-linker-flags:"/NOEXP /LIBPATH:""C:\Users\lem0nify\code\odin\path with spaces"""
Invalid flag: with
Invalid flag: spaces
[SYSTEM CALL] msvc-link
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/link.exe" "C:/Users/lem0nify/code/odin/example/example.obj"   -OUT:"C:/Users/lem0nify/code/odin/example/example.exe"  /LIBPATH:"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64" /LIBPATH:"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/ucrt/x64" /LIBPATH:"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/lib/x64" /ENTRY:mainCRTStartup /defaultlib:libcmt /NOIMPLIB /NOEXP /nologo /incremental:no /opt:ref /subsystem:CONSOLE /machine:x64  /NOEXP /LIBPATH:C:\Users\lem0nify\code\odin\path  "kernel32.lib" "foo.lib"

LINK : fatal error LNK1181: cannot open input file 'foo.lib'

Steps to Reproduce

  1. get Windows environment
  2. place any static library (.lib) at path containing spaces
  3. try to compile program which links to in, passing linker flag /LIBPATH to specify library location

Additional notes

I have also tried similar steps on Linux, but the issue is not present there.

Beefster09 commented 1 year ago

I noticed this too. You can work around this by escaping spaces with carets, but this feels... uncomfortable.