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

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

Open
AregevDev opened this issue Jul 6, 2024 · 3 comments
Open

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

AregevDev opened this issue Jul 6, 2024 · 3 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

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

2 participants