Repository: conan-io/conan-center-index

Issue:
[package] icu/67.1: can't compile on Windows
<!-- 
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.
-->

### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **icu/67.1**
  * Operating System+version: **Windows 10**
  * Compiler+version: **MSVC 2019**
  * Conan version: **conan 1.28.1**


### Conan profile
```
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.cppstd=14
compiler.runtime=MD
compiler.version=16
os=Windows
os_build=Windows
[options]
*:fPIC=True
*:shared=False
*:static=True
[build_requires]
[env]
```


### Steps to reproduce (Include if Applicable)
conan install icu/67.1@ --build "*"


### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.cppstd=14
compiler.runtime=MD
compiler.version=16
os=Windows
os_build=Windows
[options]
*:fPIC=True
*:shared=False
*:static=True
[build_requires]
[env]

icu/67.1: Forced build from source
Installing package: icu/67.1
Requirements
    icu/67.1 from 'artifactory' - Cache
Packages
    icu/67.1:1227fdf5511e684ad7c925afa05d82715a7d91b5 - Build

Installing (downloading, building) binaries...
icu/67.1: WARN: Build folder is dirty, removing it: D:\.conan\.data\icu\67.1\_\_\build\1227fdf5511e684ad7c925afa05d82715a7d91b5
icu/67.1: Copying sources to build folder
icu/67.1: Building your package in D:\.conan\.data\icu\67.1\_\_\build\1227fdf5511e684ad7c925afa05d82715a7d91b5
icu/67.1: Generator txt created conanbuildinfo.txt
icu/67.1: Calling build()
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.7.1
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
icu/67.1: run_in_windows_bash: "C:\Program Files\Git\bin\bash.exe" --login -c ^"cd \^"/d/.conan/.data/icu/67.1/_/_/build/1227fdf5511e684ad7c925afa05d82715a7d91b5/source_subfolder/build\^" ^&^& ../source/runConfigureICU Cygwin/MSVC --prefix=D:/.conan/.data/icu/67.1/_/_/package/1227fdf5511e684ad7c925afa05d82715a7d91b5 --with-library-bits=64 --disable-samples --disable-layout --disable-layoutex --disable-extras --with-data-packaging=archive --datarootdir=D:/.conan/.data/icu/67.1/_/_/package/1227fdf5511e684ad7c925afa05d82715a7d91b5/lib --sbindir=D:/.conan/.data/icu/67.1/_/_/package/1227fdf5511e684ad7c925afa05d82715a7d91b5/bin --enable-static --disable-shared --disable-tests ^"
icu/67.1: export CPP= CC=cl CXX=cl CPPFLAGS=-DNDEBUG -DU_STATIC_IMPLEMENTATION CFLAGS=-Gy -MD -O2 -Ob2 -MD CXXFLAGS=-Gy -MD -O2 -Ob2 -MD /std:c++14 LDFLAGS= MAKE=
icu/67.1: Running ./configure  --prefix=D:/.conan/.data/icu/67.1/_/_/package/1227fdf5511e684ad7c925afa05d82715a7d91b5 --with-library-bits=64 --disable-samples --disable-layout --disable-layoutex --disable-extras --with-data-packaging=archive --datarootdir=D:/.conan/.data/icu/67.1/_/_/package/1227fdf5511e684ad7c925afa05d82715a7d91b5/lib --sbindir=D:/.conan/.data/icu/67.1/_/_/package/1227fdf5511e684ad7c925afa05d82715a7d91b5/bin --enable-static --disable-shared --disable-tests for Windows with Cygwin using Microsoft Visual C++ compiler
icu/67.1:
icu/67.1: checking for ICU version numbers... release 67.1, library 67.1, unicode version 13.0
icu/67.1: checking build system type... x86_64-pc-mingw64
icu/67.1: checking host system type... x86_64-pc-mingw64
icu/67.1: checking whether to build debug libraries... no
icu/67.1: checking whether to build release libraries... yes
icu/67.1: checking whether the C compiler works... yes
icu/67.1: checking for C compiler default output file name... conftest.exe
icu/67.1: checking for suffix of executables... .exe
icu/67.1: checking whether we are cross compiling... no
icu/67.1: checking for suffix of object files... obj
icu/67.1: checking whether we are using the GNU C compiler... no
icu/67.1: checking whether cl accepts -g... yes
icu/67.1: checking for cl option to accept ISO C89... none needed
icu/67.1: checking whether we are using the GNU C++ compiler... no
icu/67.1: checking whether cl accepts -g... yes
icu/67.1: checking for pkg-config... no
icu/67.1: checking for ICULEHB... no
icu/67.1: checking how to run the C preprocessor... cl -E
icu/67.1: checking for a BSD-compatible install... /usr/bin/install -c
icu/67.1: checking for python3... python3
icu/67.1: checking for gmake... no
icu/67.1: checking for gnumake... no
icu/67.1: checking for doxygen... no
icu/67.1: configure: error: link.exe is not a valid linker. Your PATH is incorrect.
icu/67.1:                   Please follow the directions in ICU's readme.
icu/67.1: ../source/runConfigureICU: ./configure failed
icu/67.1:
icu/67.1: ERROR: Package '1227fdf5511e684ad7c925afa05d82715a7d91b5' build failed
icu/67.1: WARN: Build folder D:\.conan\.data\icu\67.1\_\_\build\1227fdf5511e684ad7c925afa05d82715a7d91b5
ERROR: icu/67.1: Error in build() method, line 94
        self.run(self._build_config_cmd, win_bash=tools.os_info.is_windows)
        ConanException: Error 1 while executing ../source/runConfigureICU Cygwin/MSVC --prefix=D:/.conan/.data/icu/67.1/_/_/package/1227fdf5511e684ad7c925afa05d82715a7d91b5 --with-library-bits=64 --disable-samples --disable-layout --disable-layoutex --disable-extras --with-data-packaging=archive --datarootdir=D:/.conan/.data/icu/67.1/_/_/package/1227fdf5511e684ad7c925afa05d82715a7d91b5/lib --sbindir=D:/.conan/.data/icu/67.1/_/_/package/1227fdf5511e684ad7c925afa05d82715a7d91b5/bin --enable-static --disable-shared --disable-tests
```

</details>



Discussion:
Are you running this from `cygwin` or `msys2`, instead of a plain `cmd`?
I *think* the configure script is picking up a `link.exe`, provided by cygwin.
Try running `conan create` from `cmd` and make sure that no bash.exe/link.exe is in your PATH.
I am running the command from plain CMD.

**>echo %PATH%**
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;C:\Program Files\Conan\conan;C:\Users\malas\AppData\Local\Microsoft\WindowsApps;C:\Program Files\CMake\bin;;C:\Program Files\Git\bin;;C:\Program Files\Docker\Docker\resources\bin;C:\Users\malas\anaconda3;C:\Users\malas\anaconda3\Library\mingw-w64\bin;C:\Users\malas\anaconda3\Library\usr\bin;C:\Users\malas\anaconda3\Library\bin;C:\Users\malas\anaconda3\Scripts;C:\Program Files\Conan\conan;C:\Users\malas\AppData\Local\Microsoft\WindowsApps

**>where link.exe**
INFO: Could not find files for the given pattern(s).
Don't know if it can help you, but when I have `MinGW` in my PATH, I have to add `CC=cl.exe` and `CXX=cl.exe` to my Visual Studio conan's profile in order to avoid that autoconf chose GNU compiler/linker instead of Visual Studio compiler/linker.
I don't see `msys2` or any other build requirement in your build requirements,
so I assume bash.exe is in your path somewhere.
Maybe it is provided by anaconda, git, or mingw itself?
Recently, I had a similar problem using cygwin where the linker picked up cygwin's link.exe instead of MSVC's link.exe.

Enable [`CONAN_PRINT_RUN_COMMANDS`](https://docs.conan.io/en/latest/reference/conanfile/other.html#running-commands) to see what command is run to configure.
Can the problem somehow be solved by conan itself? Shouldn't it use the proper linker provided by MSVC with higher priority? Maybe I should rephrase the request and post it somewhere else?
@AndreyMlashkin 
I agree, your environment (which has bash) interferes with icu.

Can you try 3 things?
1. Try applying the following patch:
    ```patch
    --- a/recipes/icu/all/conanfile.py
    +++ b/recipes/icu/all/conanfile.py
    @@ -60,8 +60,7 @@ class ICUBase(ConanFile):
             del self.info.options.silent  # Verbosity doesn't affect package's ID
     
         def build_requirements(self):
    -        if tools.os_info.is_windows and "CONAN_BASH_PATH" not in os.environ and \
    -                tools.os_info.detect_windows_subsystem() != "msys2":
    +        if tools.os_info.is_windows and "CONAN_BASH_PATH" not in os.environ:
                 self.build_requires("msys2/20200517")
     
         def source(self):
    ```
    and run `conan create . icu/67.1` afterwards
2. Keep the patch applied and reduce your PATH the the bare minimum and run from cmd.
e.g.:
    ```
    set PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\ProgramData\chocolatey\bin;C:\Program Files\Conan\conan;C:\Users\malas\AppData\Local\Microsoft\WindowsApps;C:\Program Files\CMake\bin;C:\Program Files\Git\bin;C:\Users\malas\AppData\Local\Microsoft\WindowsApps
    conan create . icu/67.1@
    ```
3. Undo the patch from step 1 but run `conan create` again with the reduced PATH.
   
1. Applying the patch solved the problem
2. Works even with minimal path
3. The same error as before

Resolving patch:
diff --git a/recipes/icu/all/conanfile.py b/recipes/icu/all/conanfile.py
--- a/recipes/icu/all/conanfile.py
+++ b/recipes/icu/all/conanfile.py
@@ -60,8 +60,7 @@ def package_id(self):
         del self.info.options.silent  # Verbosity doesn't affect package's ID
 
     def build_requirements(self):
-        if tools.os_info.is_windows and "CONAN_BASH_PATH" not in os.environ and \
-                tools.os_info.detect_windows_subsystem() != "msys2":
+        if tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH"):
             self.build_requires("msys2/20200517")
 
     def source(self):


Test patch: