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

could not find X11 #1180

Open
4 of 11 tasks
cstkingkey opened this issue Jan 2, 2023 · 8 comments
Open
4 of 11 tasks

could not find X11 #1180

cstkingkey opened this issue Jan 2, 2023 · 8 comments
Labels
Milestone

Comments

@cstkingkey
Copy link

Checklist

Describe your issue

build fltk-rs (https://github.com/fltk-rs/fltk-rs) with https://github.com/fltk-rs/fltk-rs
run into
-- Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB)
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Pango requires Xft but Xft library or headers could not be found.
-- Please install Xft development files and try again or disable OPTION_USE_PANGO.
-- Configuring incomplete, errors occurred!

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.4

Example

No response

Additional information / notes

No response

@cstkingkey
Copy link
Author

following packages are installed in the custom image
libx11-dev:arm64 libxext-dev:arm64 libxft-dev:arm64 libxinerama-dev:arm64 libxcursor-dev:arm64 libxrender-dev:arm64 libxfixes-dev:arm64 libwayland-dev:arm64 wayland-protocols libdbus-1-dev:arm64 libxkbcommon-dev:arm64 libpango1.0-dev:arm64 libgl1-mesa-dev:arm64 libglu1-mesa-dev:arm64

@cstkingkey
Copy link
Author

Image is built with cross aa59bf2 using cargo build-docker-image

@Emilgardis
Copy link
Member

How exactly are you installing these dependencies in the custom image built with cargo build-docker-image?

@cstkingkey
Copy link
Author

How exactly are you installing these dependencies in the custom image built with cargo build-docker-image?

get the base image with cargo build-docker-image, then build the custom image with following Dockerfile

FROM ghcr.io/cross-rs/aarch64-unknown-linux-gnu:local

ENV DEBIAN_FRONTEND=noninteractive

RUN dpkg --add-architecture arm64 &&
apt-get update &&
apt-get install --assume-yes --no-install-recommends
libx11-dev:arm64 libxext-dev:arm64 libxft-dev:arm64
libxinerama-dev:arm64 libxcursor-dev:arm64
libxrender-dev:arm64 libxfixes-dev:arm64
libwayland-dev:arm64 wayland-protocols libdbus-1-dev:arm64 libxkbcommon-dev:arm64
libpango1.0-dev:arm64 libgl1-mesa-dev:arm64 libglu1-mesa-dev:arm64

@Emilgardis
Copy link
Member

Alright, this might be an issue with how fltk-sys (or really the cmake build) discovers packages.

Any reason you're using cargo build-docker-image and not any of the options listed in the wiki?

Does setting X11_X11_INCLUDE_PATH and X11_X11_LIB solve the issue?

It should be X11_X11_LIB=/usr/lib/aarch64-linux-gnu/ and X11_X11_INCLUDE_PATH=/usr/include/X11/

@cstkingkey
Copy link
Author

Alright, this might be an issue with how fltk-sys (or really the cmake build) discovers packages.

Any reason you're using cargo build-docker-image and not any of the options listed in the wiki?

Does setting X11_X11_INCLUDE_PATH and X11_X11_LIB solve the issue?

It should be X11_X11_LIB=/usr/lib/aarch64-linux-gnu/ and X11_X11_INCLUDE_PATH=/usr/include/X11/

No, same error log.
The reason is not very straightforward.
I try to build macos image. Then I try to update the linux arm64 image as the one I'm using is pretty old which is based on rustembedded/cross:aarch64-unknown-linux-gnu.

@cstkingkey
Copy link
Author

comment out following code in toolchain.cmake will make it work
if(DEFINED ENV{CROSS_SYSROOT})
set(CMAKE_FIND_ROOT_PATH "$ENV{CROSS_SYSROOT}" "${CMAKE_PREFIX_PATH}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
endif()

@MoAlyousef
Copy link

MoAlyousef commented Jan 11, 2023

The set(CMAKE_FIND_ROOT_PATH "$ENV{CROSS_SYSROOT}" "${CMAKE_PREFIX_PATH}") seems wrong.

CMAKE_PREFIX_PATH is empty by default, and is only filled if a path is given using set(CMAKE_PREFIX_PATH some/path) or using the command-line: cmake -B bin -DCMAKE_PREFIX_PATH=some/path.
Also for example on aarch64-linux-gnu, CROSS_SYSROOT is set to /usr/aarch64-linux-gnu, this makes searching for libs and headers happen in $CROSS_SYSROOT/include and $CROSS_SYSROOT/lib, while in reality, they are installed in /usr/include/aarch64-linux-gnu/ and /usr/lib/aarch64-linux-gnu.

I can confirm fltk-rs used to build using cross-rs, but currently it doesn't with:

FROM ghcr.io/cross-rs/aarch64-unknown-linux-gnu:edge

ENV DEBIAN_FRONTEND=noninteractive

RUN dpkg --add-architecture arm64 && \
    apt-get update && \
    apt-get install --assume-yes --no-install-recommends \
    libx11-dev:arm64 libxext-dev:arm64 libxft-dev:arm64 \
    libxinerama-dev:arm64 libxcursor-dev:arm64 \
    libxrender-dev:arm64  libxfixes-dev:arm64  libgl1-mesa-dev:arm64 \
    libglu1-mesa-dev:arm64 libasound2-dev:arm64 libpango1.0-dev:arm64

and Cross.toml:

[target.aarch64-unknown-linux-gnu]
dockerfile = "./arm64-dockerfile"
cross build --target aarch64-unknown-linux-gnu

I think cross-rs shouldn't be passing a CMAKE_TOOLCHAIN_FILE to every build since that breaks any repo which uses its own toolchain file or using a toolchain file provided by a vendor, like the android cmake toolchain file for example.

A minimal repro using the cmake crate (only requiring X11, no fltk):

|
|__csrc
|        |_lib.c
|        |_CMakeLists.txt
|_src
|     |_main.rs
|
|_Cargo.toml
|
|_Cross.toml
|
|_build.rs
|
|_arm64-dockerfile
// build.rs
fn main() {
    let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
    let _dst = cmake::Config::new("csrc").build();
    println!(
        "cargo:rustc-link-search=native={}",
        out_dir.join("lib").display()
    );
    println!("cargo:rustc-link-lib=static=cx11");
}
# Cargo.toml
[package]
name = "cros2"
version = "0.1.0"
edition = "2021"

[build-dependencies]
cmake = "*"
# Cross.toml
[target.aarch64-unknown-linux-gnu]
dockerfile = "./arm64-dockerfile"
# arm64-dockerfile
FROM ghcr.io/cross-rs/aarch64-unknown-linux-gnu:edge

ENV DEBIAN_FRONTEND=noninteractive

RUN dpkg --add-architecture arm64 && \
    apt-get update && \
    apt-get install --assume-yes --no-install-recommends \
    libx11-dev:arm64
// csrc/lib.c
int cmain() {
    return 0;
}
# csrc/CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(cx11)

find_package(X11 REQUIRED) # this will fail
add_library(cx11 lib.c)

# cmake-rs requires an install target
install(TARGETS cx11
    EXPORT cx11Config
    ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
    LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
    )
// src/main.rs
fn main() {
    println!("Hello, world!");
}

build with cross build --target=aarch64-unknown-linux-gnu will also fail with a similar error.

@Emilgardis Emilgardis added the A-cmake Area: Cmake compiler label May 30, 2023
@Emilgardis Emilgardis added this to the v0.3.1 milestone Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants