Skip to content

Cmake cannot find Visual Studio under the MSVC cross image #60

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

Closed
AregevDev opened this issue Jul 6, 2024 · 7 comments
Closed

Cmake cannot find Visual Studio under the MSVC cross image #60

AregevDev opened this issue Jul 6, 2024 · 7 comments

Comments

@AregevDev
Copy link

Hello, I am trying to use the x86_64-pc-windows-msvc docker image. I can compile a "hello world" program. However, when trying to build raylib-sys, the build fails:

[oak@compooter samples]$ cross build --target x86_64-pc-windows-msvc --bin logo
warning: value assigned to `profile` is never read
  --> /home/oak/Documents/raylib-rs/raylib-sys/build.rs:65:13
   |
65 |     let mut profile = "";
   |             ^^^^^^^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_assignments)]` on by default

warning: `raylib-sys` (build script) generated 1 warning
   Compiling raylib-sys v5.0.1 (/home/oak/Documents/raylib-rs/raylib-sys)
error: failed to run custom build command for `raylib-sys v5.0.1 (/home/oak/Documents/raylib-rs/raylib-sys)`

Caused by:
  process didn't exit successfully: `/target/debug/build/raylib-sys-5bc5bad159c96967/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-changed=./binding/binding.h
  CMAKE_GENERATOR_x86_64-pc-windows-msvc = None
  CMAKE_GENERATOR_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_x86_64-pc-windows-msvc = None
  CMAKE_PREFIX_PATH_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-pc-windows-msvc = None
  CMAKE_x86_64_pc_windows_msvc = None
  TARGET_CMAKE = None
  CMAKE = None

  --- stderr
  thread 'main' panicked at /cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:955:25:


  couldn't determine visual studio generator
  if VisualStudio is installed, however, consider running the appropriate vcvars script before building this crate

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

How can I run vcvarsall.bat before running the build command?

@AregevDev AregevDev changed the title Cannot find link.exe when building CMake projects. Cmake cannot find Visual Studio under the MSVC cross image Jul 6, 2024
@Emilgardis
Copy link
Member

Interesting! I thought this was fixed but seems it's a different issue that wasn't fixed with rust-lang/cc-rs#907.

The problem is that find_vs_version expects a version to be defined.
We should probably set VisualStudioVersion=17.0 here

relevant lines in cmake:
https://github.com/rust-lang/cmake-rs/blob/c4a60dd154dd90e469dffc41a1faa717704f90b3/src/lib.rs#L943C17-L943C33

and fix in cc that removed a bunch of assumptions
rust-lang/cc-rs#907

can you try adding

#Cross.toml
[target.x86_64-pc-windows-msvc.env]
passthrough = ["VisualStudioVersion=17.0"]

@AregevDev
Copy link
Author

AregevDev commented Jul 7, 2024

I added the passthrough variable, and it cannot find the Visual Studio generator. msvc-wine's repo said cmake is supported under ninja or make. I get this error when trying to use make:

[oak@compooter samples]$ cross build --target x86_64-pc-windows-msvc --bin logo
warning: value assigned to `profile` is never read
  --> /home/oak/Documents/raylib-rs/raylib-sys/build.rs:65:13
   |
65 |     let mut profile = "";
   |             ^^^^^^^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_assignments)]` on by default

warning: `raylib-sys` (build script) generated 1 warning
   Compiling raylib-sys v5.0.1 (/home/oak/Documents/raylib-rs/raylib-sys)
error: failed to run custom build command for `raylib-sys v5.0.1 (/home/oak/Documents/raylib-rs/raylib-sys)`

Caused by:
  process didn't exit successfully: `/target/debug/build/raylib-sys-5bc5bad159c96967/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-changed=./binding/binding.h
  CMAKE_TOOLCHAIN_FILE_x86_64-pc-windows-msvc = None
  CMAKE_TOOLCHAIN_FILE_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_PREFIX_PATH_x86_64-pc-windows-msvc = None
  CMAKE_PREFIX_PATH_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-pc-windows-msvc = None
  CMAKE_x86_64_pc_windows_msvc = None
  TARGET_CMAKE = None
  CMAKE = None
  running: cd "/target/x86_64-pc-windows-msvc/debug/build/raylib-sys-92e1cacfa9e5f70f/out/build" && CMAKE_PREFIX_PATH="" "cmake" "/target/x86_64-pc-windows-msvc/debug/build/raylib-sys-92e1cacfa9e5f70f/out/raylib" "-Thost=x64" "-Ax64" "-G" "Unix Makefiles" "-DCMAKE_BUILD_TYPE=Debug" "-DBUILD_EXAMPLES=OFF" "-DCMAKE_BUILD_TYPE=Debug" "-DSUPPORT_BUSY_WAIT_LOOP=OFF" "-DSUPPORT_FILEFORMAT_JPG=ON" "-DRAYMATH_STATIC_INLINE=ON" "-DUSE_WAYLAND=OFF" "-DOPENGL_VERSION=OFF" "-DPLATFORM=Desktop" "-DCMAKE_SYSTEM_NAME=Windows" "-DCMAKE_SYSTEM_PROCESSOR=AMD64" "-DCMAKE_INSTALL_PREFIX=/target/x86_64-pc-windows-msvc/debug/build/raylib-sys-92e1cacfa9e5f70f/out" "-DCMAKE_C_FLAGS= -nologo -MD -Brepro" "-DCMAKE_C_COMPILER=/opt/msvc/bin/x64/cl.exe" "-DCMAKE_CXX_FLAGS= -nologo -MD -Brepro" "-DCMAKE_CXX_COMPILER=/opt/msvc/bin/x64/cl.exe" "-DCMAKE_ASM_FLAGS= -nologo -MD -Brepro" "-DCMAKE_ASM_COMPILER=/opt/msvc/bin/x64/cl.exe"
  -- Configuring incomplete, errors occurred!
  See also "/target/x86_64-pc-windows-msvc/debug/build/raylib-sys-92e1cacfa9e5f70f/out/build/CMakeFiles/CMakeOutput.log".

  --- stderr
  CMake Error at CMakeLists.txt:2 (project):
    Generator

      Unix Makefiles

    does not support platform specification, but platform

      x64

    was specified.


  thread 'main' panicked at /cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:1098:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[oak@compooter samples]$ 

I think we'll need a cmake toolchain file to specify the generator and remove that -A flag. I am not sure if there's a way to specify a system-wide toolchain. I want to avoid modifying raylib-sys's cmake file / build.rs

@AregevDev
Copy link
Author

Also maybe add ninja to the image file

@balins
Copy link

balins commented Sep 25, 2024

Got similar error when cross compiling for MSVC toolchain on macOS:

error: failed to run custom build command for `turbojpeg-sys v1.0.0`

Caused by:
  process didn't exit successfully: `/target/release/build/turbojpeg-sys-d0da2978281185b7/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_TURBOJPEG_STATIC
  X86_64_PC_WINDOWS_MSVC_TURBOJPEG_STATIC unset
  cargo:rerun-if-env-changed=TURBOJPEG_STATIC
  TURBOJPEG_STATIC unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_TURBOJPEG_DYNAMIC
  X86_64_PC_WINDOWS_MSVC_TURBOJPEG_DYNAMIC unset
  cargo:rerun-if-env-changed=TURBOJPEG_DYNAMIC
  TURBOJPEG_DYNAMIC unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_TURBOJPEG_SHARED
  X86_64_PC_WINDOWS_MSVC_TURBOJPEG_SHARED unset
  cargo:rerun-if-env-changed=TURBOJPEG_SHARED
  TURBOJPEG_SHARED unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_TURBOJPEG_SOURCE
  X86_64_PC_WINDOWS_MSVC_TURBOJPEG_SOURCE unset
  cargo:rerun-if-env-changed=TURBOJPEG_SOURCE
  TURBOJPEG_SOURCE unset
  Building turbojpeg from source
  CMAKE_TOOLCHAIN_FILE_x86_64-pc-windows-msvc = None
  CMAKE_TOOLCHAIN_FILE_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_x86_64-pc-windows-msvc = None
  CMAKE_GENERATOR_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_x86_64-pc-windows-msvc = None
  CMAKE_PREFIX_PATH_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-pc-windows-msvc = None
  CMAKE_x86_64_pc_windows_msvc = None
  TARGET_CMAKE = None
  CMAKE = None

  --- stderr
  thread 'main' panicked at /Users/balins/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.51/src/lib.rs:957:25:


  couldn't determine visual studio generator
  if VisualStudio is installed, however, consider running the appropriate vcvars script before building this crate

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After setting passthrough = ["VisualStudioVersion=17.0"] got another error:

error: failed to run custom build command for `turbojpeg-sys v1.0.0`

Caused by:
  process didn't exit successfully: `/target/release/build/turbojpeg-sys-d0da2978281185b7/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_TURBOJPEG_STATIC
  X86_64_PC_WINDOWS_MSVC_TURBOJPEG_STATIC unset
  cargo:rerun-if-env-changed=TURBOJPEG_STATIC
  TURBOJPEG_STATIC unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_TURBOJPEG_DYNAMIC
  X86_64_PC_WINDOWS_MSVC_TURBOJPEG_DYNAMIC unset
  cargo:rerun-if-env-changed=TURBOJPEG_DYNAMIC
  TURBOJPEG_DYNAMIC unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_TURBOJPEG_SHARED
  X86_64_PC_WINDOWS_MSVC_TURBOJPEG_SHARED unset
  cargo:rerun-if-env-changed=TURBOJPEG_SHARED
  TURBOJPEG_SHARED unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_TURBOJPEG_SOURCE
  X86_64_PC_WINDOWS_MSVC_TURBOJPEG_SOURCE unset
  cargo:rerun-if-env-changed=TURBOJPEG_SOURCE
  TURBOJPEG_SOURCE unset
  Building turbojpeg from source
  CMAKE_TOOLCHAIN_FILE_x86_64-pc-windows-msvc = None
  CMAKE_TOOLCHAIN_FILE_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_x86_64-pc-windows-msvc = None
  CMAKE_GENERATOR_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_x86_64-pc-windows-msvc = None
  CMAKE_PREFIX_PATH_x86_64_pc_windows_msvc = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-pc-windows-msvc = None
  CMAKE_x86_64_pc_windows_msvc = None
  TARGET_CMAKE = None
  CMAKE = None
  running: cd "/target/x86_64-pc-windows-msvc/release/build/turbojpeg-sys-25f4a56e1f43d8ca/out/build" && CMAKE_PREFIX_PATH="" "cmake" "/Users/balins/.cargo/registry/src/index.crates.io-6f17d22bba15001f/turbojpeg-sys-1.0.0/libjpeg-turbo" "-G" "Visual Studio 17 2022" "-Thost=x64" "-Ax64" "-DCMAKE_INSTALL_DEFAULT_LIBDIR=lib" "-DCMAKE_SYSTEM_NAME=Windows" "-DCMAKE_SYSTEM_PROCESSOR=AMD64" "-DCMAKE_INSTALL_PREFIX=/target/x86_64-pc-windows-msvc/release/build/turbojpeg-sys-25f4a56e1f43d8ca/out" "-DCMAKE_C_FLAGS= -nologo -MD -Brepro" "-DCMAKE_C_FLAGS_RELEASE= -nologo -MD -Brepro" "-DCMAKE_C_COMPILER=/opt/msvc/bin/x64/cl.exe" "-DCMAKE_CXX_FLAGS= -nologo -MD -Brepro" "-DCMAKE_CXX_FLAGS_RELEASE= -nologo -MD -Brepro" "-DCMAKE_CXX_COMPILER=/opt/msvc/bin/x64/cl.exe" "-DCMAKE_ASM_FLAGS= -nologo -MD -Brepro" "-DCMAKE_ASM_FLAGS_RELEASE= -nologo -MD -Brepro" "-DCMAKE_ASM_COMPILER=/opt/msvc/bin/x64/cl.exe" "-DCMAKE_BUILD_TYPE=Release" "-DENABLE_SHARED=0" "-DENABLE_STATIC=1" "-DREQUIRE_SIMD=ON"

  --- stderr
  CMake Error: Could not create named generator Visual Studio 17 2022

  Generators
    Green Hills MULTI            = Generates Green Hills MULTI files
                                   (experimental, work-in-progress).
  * Unix Makefiles               = Generates standard UNIX makefiles.
    Ninja                        = Generates build.ninja files.
    Ninja Multi-Config           = Generates build-<Config>.ninja files.
    Watcom WMake                 = Generates Watcom WMake makefiles.
    CodeBlocks - Ninja           = Generates CodeBlocks project files.
    CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
    CodeLite - Ninja             = Generates CodeLite project files.
    CodeLite - Unix Makefiles    = Generates CodeLite project files.
    Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
    Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
    Kate - Ninja                 = Generates Kate project files.
    Kate - Unix Makefiles        = Generates Kate project files.
    Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
    Sublime Text 2 - Unix Makefiles
                                 = Generates Sublime Text 2 project files.

  thread 'main' panicked at /Users/balins/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.51/src/lib.rs:1100:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@cavivie
Copy link
Contributor

cavivie commented Oct 23, 2024

The issue is that cmake-rs is using a version of cc-rs lower than 1.0.89, because the feature of finding vs tools on non-windows hosts has been released since 1.0.89.

@cavivie
Copy link
Contributor

cavivie commented Oct 23, 2024

@Emilgardis I think this issue can be closed here and should be moved to cmake-rs.

@Emilgardis
Copy link
Member

aha! Yes, 1.0.89 is required for it to work at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants