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

Compile from source without pre-built deps failed #45645

Closed
6 of 11 tasks
inkydragon opened this issue Jun 11, 2022 · 19 comments · May be fixed by #45712
Closed
6 of 11 tasks

Compile from source without pre-built deps failed #45645

inkydragon opened this issue Jun 11, 2022 · 19 comments · May be fixed by #45712
Labels
domain:building Build system, or building Julia or its dependencies domain:ci Continuous integration system:windows Affects only Windows

Comments

@inkydragon
Copy link
Sponsor Member

inkydragon commented Jun 11, 2022

error list

Some patches may need to be backported to v1.7, v1.8

env

  • Win 10 21H2
  • CYGWIN_NT-10.0 wos-PC 3.3.4(0.341/5/3) 2022-01-31 19:35 x86_64 Cygwin
  • cc, gcc, g++, x86_64-w64-mingw32-gcc, x86_64-w64-mingw32-gfortran 11.2.0
  • GNU Make 4.3
  • cmake version 3.20.0
  • Python 3.9.10

Make.user

XC_HOST = x86_64-w64-mingw32
USE_BINARYBUILDER=0

compile steps:

make O=julia-win64 configure
echo 'XC_HOST = x86_64-w64-mingw32' > julia-win64/Make.user
echo 'USE_BINARYBUILDER=0' >> julia-win64/Make.user
echo 'ifeq ($(BUILDROOT),$(JULIAHOME))
        $(error "in-tree build disabled")
      endif' >> Make.user
make -C julia-win64

julia source verison master

@inkydragon

This comment was marked as resolved.

@inkydragon
Copy link
Sponsor Member Author

inkydragon commented Jun 12, 2022

llvm build error

long error log

error

Consolidate compiler generated dependencies of target LLVMSupport
make[8]: Leaving directory '/cygdrive/v/julia/julia-win64/deps/llvm-julia-13.0.1-0/build_Release/NATIVE'
make  -f lib/Support/CMakeFiles/LLVMSupport.dir/build.make lib/Support/CMakeFiles/LLVMSupport.dir/build
make[8]: Entering directory '/cygdrive/v/julia/julia-win64/deps/llvm-julia-13.0.1-0/build_Release/NATIVE'
[  0%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/ThreadLocal.cpp.o
cd /cygdrive/v/julia/julia-win64/deps/llvm-julia-13.0.1-0/build_Release/NATIVE/lib/Support && /usr/bin/g++ -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/cygdrive/v/julia/julia-win64/deps/llvm-julia-13.0.1-0/build_Release/NATIVE/lib/Support -I/cygdrive/v/julia/deps/srccache/llvm-julia-13.0.1-0/llvm/lib/Support -I/cygdrive/v/julia/julia-win64/deps/llvm-julia-13.0.1-0/build_Release/NATIVE/include -I/cygdrive/v/julia/deps/srccache/llvm-julia-13.0.1-0/llvm/include -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wmisleading-indentation -O3 -DNDEBUG -std=gnu++14  -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/ThreadLocal.cpp.o -MF CMakeFiles/LLVMSupport.dir/ThreadLocal.cpp.o.d -o CMakeFiles/LLVMSupport.dir/ThreadLocal.cpp.o -c /cygdrive/v/julia/deps/srccache/llvm-julia-13.0.1-0/llvm/lib/Support/ThreadLocal.cpp
In file included from /cygdrive/v/julia/deps/srccache/llvm-julia-13.0.1-0/llvm/lib/Support/ThreadLocal.cpp:42:
/cygdrive/v/julia/deps/srccache/llvm-julia-13.0.1-0/llvm/lib/Support/Unix/ThreadLocal.inc: In member function 'void llvm::sys::ThreadLocalImpl::setInstance(const void*)':
/cygdrive/v/julia/deps/srccache/llvm-julia-13.0.1-0/llvm/lib/Support/Unix/ThreadLocal.inc:66:57: error: incompatible types in assignment of 'void*' to 'char [8]'
   66 | void ThreadLocalImpl::setInstance(const void* d) { data = const_cast<void*>(d);}
      |                                                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~
make[8]: *** [lib/Support/CMakeFiles/LLVMSupport.dir/build.make:1952: lib/Support/CMakeFiles/LLVMSupport.dir/ThreadLocal.cpp.o] Error 1

make call /usr/bin/g++, It is probably that the compile flag was not passed correctly.

Or we may update LLVM to julia-13.0.1-1.

solution

fix patch
Maybe this is a bug, and need to backport a patch?

JuliaLang/llvm-project@d351f54

link error: cannot find lib

julia/deps/llvm.mk

Lines 200 to 204 in a9e3cc7

# change the SONAME of Julia's private LLVM
# i.e. libLLVM-6.0jl.so
# see #32462
LLVM_CMAKE += -DLLVM_VERSION_SUFFIX:STRING="jl"
LLVM_CMAKE += -DLLVM_SHLIB_SYMBOL_VERSION:STRING="JL_LLVM_$(LLVM_VER_SHORT)"

solution

libLLVM.dll now called libLLVM-13jl.dll

fix patch

diff --git a/deps/llvm.mk b/deps/llvm.mk
index e0512137da..ecc7756e03 100644
--- a/deps/llvm.mk
+++ b/deps/llvm.mk
@@ -258,7 +258,7 @@ LLVM_INSTALL = \
     cp -r $$(SRCCACHE)/$$(LLVM_SRC_DIR)/llvm/utils/lit $2$$(build_depsbindir)/ && \
     $$(CMAKE) -DCMAKE_INSTALL_PREFIX="$2$$(build_prefix)" -P cmake_install.cmake
 ifeq ($(OS), WINNT)
-LLVM_INSTALL += && cp $2$$(build_shlibdir)/libLLVM.dll $2$$(build_depsbindir)
+LLVM_INSTALL += && cp $2$$(build_shlibdir)/libLLVM-*.dll $2$$(build_depsbindir)/libLLVM.dll
 endif
 ifeq ($(OS),Darwin)
 # https://github.com/JuliaLang/julia/issues/29981

Maybe macOS's command need a patch too?

julia/deps/llvm.mk

Lines 260 to 266 in a9e3cc7

ifeq ($(OS), WINNT)
LLVM_INSTALL += && cp $2$$(build_shlibdir)/libLLVM.dll $2$$(build_depsbindir)
endif
ifeq ($(OS),Darwin)
# https://github.com/JuliaLang/julia/issues/29981
LLVM_INSTALL += && ln -s libLLVM.dylib $2$$(build_shlibdir)/libLLVM-$$(LLVM_VER_SHORT).dylib
endif

Intermittent build errors in cygwin

bash - cygwin cp can't copy file "abc" because destination dir. contains file "abc.exe" - Stack Overflow

cp -r $$(SRCCACHE)/$$(LLVM_SRC_DIR)/llvm/utils/lit $2$$(build_depsbindir)/ && \

cygwin sometimes fails when copying test files which located in the llvm/utils/lit folder.

solution

  • workaround: A possible solution is to force cp to always return true:
-    cp -r $$(SRCCACHE)/$$(LLVM_SRC_DIR)/llvm/utils/lit $2$$(build_depsbindir)/ && \
+    cp -r $$(SRCCACHE)/$$(LLVM_SRC_DIR)/llvm/utils/lit $2$$(build_depsbindir)/ || true && \

@inkydragon inkydragon changed the title [win] Offline source code build with full deps failed Offline source code build with full deps failed Jun 12, 2022
@inkydragon inkydragon changed the title Offline source code build with full deps failed Compile from source without pre-built deps failed Jun 12, 2022
@inkydragon
Copy link
Sponsor Member Author

inkydragon commented Jun 12, 2022

libgit2 <- libssh2

When building libgit2, sometimes libssh2 is not found

solution 1 - use mbedTLS for libssh2

I'm not sure if this patch is necessary or not. More tests needed.

patches
diff --git a/deps/libssh2.mk b/deps/libssh2.mk
index e27a57a407..8a17c814dd 100644
--- a/deps/libssh2.mk
+++ b/deps/libssh2.mk
@@ -11,11 +11,9 @@ endif
 LIBSSH2_OPTS := $(CMAKE_COMMON) -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF \
                -DCMAKE_BUILD_TYPE=Release
 
-ifeq ($(OS),WINNT)
-LIBSSH2_OPTS += -DCRYPTO_BACKEND=WinCNG -DENABLE_ZLIB_COMPRESSION=OFF        
 ifeq ($(BUILD_OS),WINNT)
+LIBSSH2_OPTS += -DCRYPTO_BACKEND=WinCNG -DENABLE_ZLIB_COMPRESSION=OFF        
 LIBSSH2_OPTS += -G"MSYS Makefiles"
-endif
 else
 LIBSSH2_OPTS += -DCRYPTO_BACKEND=mbedTLS -DENABLE_ZLIB_COMPRESSION=OFF       
 endif
diff --git a/deps/mbedtls.mk b/deps/mbedtls.mk
index 12788e1c03..5aefa98232 100644
--- a/deps/mbedtls.mk
+++ b/deps/mbedtls.mk
@@ -47,7 +47,7 @@ ifeq ($(OS),$(BUILD_OS))
 endif
        echo 1 > $@
 
-ifeq ($(OS),WINNT)
+ifeq ($(BUILD_OS),WINNT)
 define MBEDTLS_INSTALL
        mkdir -p $2/$$(build_shlibdir)
        cp $1/library/libmbedcrypto.$$(SHLIB_EXT) $2/$$(build_shlibdir)

solution 2 - use WinCNG for libssh2

and Update libgit2's build script: https://github.com/JuliaPackaging/Yggdrasil/blob/f73b0dc8ce7f6927c49d9616487092b52aff5a28/L/LibGit2/build_tarballs.jl#L36-L37

cmake cannot find bcrypt...

-LIBGIT2_OPTS += -DCMAKE_FIND_ROOT_PATH=/usr/$(XC_HOST) -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
+LIBGIT2_OPTS += -DCMAKE_FIND_ROOT_PATH=/usr/$(XC_HOST)/sys-root/mingw/ -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY

@inkydragon

This comment was marked as resolved.

@inkydragon
Copy link
Sponsor Member Author

inkydragon commented Jun 12, 2022

p7zip

error msg

On Windows, cross compile with mingw in cygwin will give errors:

$ make CC="x86_64-w64-mingw32-gcc" 7za
mkdir -p bin
make -C CPP/7zip/Bundles/Alone all
make[1]: 进入目录“/cygdrive/v/tmp/p7zip-17.04/CPP/7zip/Bundles/Alone”
x86_64-w64-mingw32-gcc -c -std=gnu11 -I. -I../../../../C -I../../../../CPP/myWindows -I../../../../CPP/include_windows -I../../../../CPP -O2 -s -pipe -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DNDEBUG -D_REENTRANT -DENV_UNIX -D_7ZIP_LARGE_PAGES  -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT -DENV_UNIX -DBREAK_HANDLER -DUNICODE -D_UNICODE -DUNIX_USE_WIN_FILE -DZSTD_MULTITHREAD -DNO_XXHASH -DFL2_7ZIP_BUILD   ../../../../C/Alloc.c
In file included from ../../../../C/Alloc.c:7:
../../../../CPP/include_windows/windows.h:81:9: 错误:未知的类型名‘WCHAR’
   81 | typedef WCHAR *LPWSTR;
      |         ^~~~~
../../../../CPP/include_windows/windows.h:82:9: 错误:未知的类型名‘CHAR’

Solution

  • workaround: 7z is just an external tool, so I'm skipping the cross-compilation for now.

Maybe p7zip doesn't support compiling on native windows.
But why MSYS2 can compile it successfully? Package: p7zip - MSYS2 Packages

It's incredibly frustrating to build p7zip on mingw, so instead we just redistribute 7z

https://github.com/JuliaPackaging/Yggdrasil/blob/b2e0c2c5851b71230fb7170f74d773393ce37f80/P/p7zip/build_tarballs.jl#L21

We should learn from Yggdrasil's build scripts.

@inkydragon

This comment was marked as resolved.

@inkydragon
Copy link
Sponsor Member Author

Finally, julia can be compiled successfully.

$ ./julia.bat
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.0-DEV.759 (2022-06-12)
 _/ |\__'_|_|_|\__'_|  |  offline-build/f97f25ea34* (fork: 4 commits, 1 day)
|__/                   |

julia> versioninfo()
Julia Version 1.9.0-DEV.759
Commit f97f25ea34* (2022-06-12 15:49 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 6 × Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 1 on 6 virtual cores

@ViralBShah ViralBShah added system:windows Affects only Windows domain:building Build system, or building Julia or its dependencies labels Jun 13, 2022
@metab0t
Copy link
Contributor

metab0t commented Jun 14, 2022

Sadly many deps are not configured correctly to invoke correct cross compiler.

@ViralBShah
Copy link
Member

@inkydragon Will you be making a PR with these?

@inkydragon
Copy link
Sponsor Member Author

inkydragon commented Jun 15, 2022

@ViralBShah Yes, I will. Maybe I'll open a draft pr later.

At the moment, I haven't found the right patch for some problems and need to manually deal with them.

  • p7zip

7z is just an external tool, so I'm skipping the cross-compilation for now.

Originally posted by @inkydragon in #45645 (comment)

Some issues may require upstream patches:

  • LLVM

Maybe this is a bug, and need to backport a patch?

JuliaLang/llvm-project@d351f54

Originally posted by @inkydragon in #45645 (comment)

@metab0t
Copy link
Contributor

metab0t commented Jun 16, 2022

@inkydragon
libssh2 name issue can be fixed by libssh2/libssh2#711

@metab0t
Copy link
Contributor

metab0t commented Jun 16, 2022

In order to correctly cross compile, we need to ensure all deps invoke the correct cross compiler:

  1. Makefile based dep: use MAKE_COMMON (we need to add CC CXX FC LDFLAGS to MAKE_COMMON)
  2. Autotool based dep: use CONFIGURE_COMMON
  3. CMake based dep: use CMAKE_COMMON (Currently zlib and LLVM does not use it)

@ViralBShah
Copy link
Member

ViralBShah commented Oct 31, 2022

If this is all fixed on master, we should close. I don't think it is worth worrying about backporting. But it would also need CI to avoid regressing.

@DilumAluthge Do we do full source CI on any platform? If so, would be good to enable Windows once @inkydragon gives us a heads up.

@ViralBShah ViralBShah added the domain:ci Continuous integration label Oct 31, 2022
@DilumAluthge
Copy link
Member

Yeah, we have full source CI on x86_64-linux-gnu.

@DilumAluthge
Copy link
Member

Although it looks like the build regressed recently. Compare a passing build on Saturday (https://buildkite.com/julialang/julia-master-scheduled/builds/140#018422c5-9cdd-4877-8ac2-e306a3add207) to a failing build on Sunday (https://buildkite.com/julialang/julia-master-scheduled/builds/141#01842c63-d05a-41c9-aea4-237e2d402f83).

@stahta01
Copy link
Contributor

What I think may be an better Cygwin LLVM copy bug work around.

Tim S.

---
 deps/llvm.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/deps/llvm.mk b/deps/llvm.mk
index 81dcff1ce4..68ae292b96 100644
--- a/deps/llvm.mk
+++ b/deps/llvm.mk
@@ -262,7 +262,7 @@ endif
 
 LLVM_INSTALL = \
 	cd $1 && mkdir -p $2$$(build_depsbindir) && \
-	cp -r $$(SRCCACHE)/$$(LLVM_SRC_DIR)/llvm/utils/lit $2$$(build_depsbindir)/ && \
+	rsync --recursive --times --perms --compress-level=0 $$(SRCCACHE)/$$(LLVM_SRC_DIR)/llvm/utils/lit $2$$(build_depsbindir)/ && \
 	$$(CMAKE) -DCMAKE_INSTALL_PREFIX="$2$$(build_prefix)" -P cmake_install.cmake
 ifeq ($(OS), WINNT)
 LLVM_INSTALL += && cp $2$$(build_shlibdir)/$(LLVM_SHARED_LIB_NAME).dll $2$$(build_depsbindir)
-- 

@inkydragon
Copy link
Sponsor Member Author

Adding a dependency may not be a good idea.

deps/llvm.mk

--LLVM_INSTALL = \
-	cd $1 && mkdir -p $2$$(build_depsbindir) && \
-	cp -r $$(SRCCACHE)/$$(LLVM_SRC_DIR)/llvm/utils/lit $2$$(build_depsbindir)/ && \
-	$$(CMAKE) -DCMAKE_INSTALL_PREFIX="$2$$(build_prefix)" -P cmake_install.cmake
+LLVM_INSTALL = cd $1 && mkdir -p $2$$(build_depsbindir)
+ifeq ($(OS), WINNT)
+# https://stackoverflow.com/questions/58048185/cygwin-cp-cant-copy-file-abc-because-destination-dir-contains-file-abc-exe
+# ON Windows (Cygwin/MSYS), you need to copy none-ext files first,
+#	then copy `.exe` files.
+LLVM_INSTALL += && cd $$(SRCCACHE)/$$(LLVM_SRC_DIR)/llvm/utils/ \
+	&& find lit/ ! -name '*.exe'  -exec cp --parents \{\} $2$$(build_depsbindir)/ \; \
+	&& find lit/   -name '*.exe'  -exec cp --parents \{\} $2$$(build_depsbindir)/ \; \
+	&& cd $(build_prefix)/../deps/$1
+else
+LLVM_INSTALL += && cp -r $$(SRCCACHE)/$$(LLVM_SRC_DIR)/llvm/utils/lit $2$$(build_depsbindir)/
+endif
+LLVM_INSTALL += && $$(CMAKE) -DCMAKE_INSTALL_PREFIX="$2$$(build_prefix)" -P cmake_install.cmake

deps/tools/common.mk

+ifneq (,$(findstring MINGW,$(shell uname)))
+# Win + MSYS/MINGW
+# Or you may add `.exe` to the full path
+CMAKE_COMMON += -DCMAKE_C_COMPILER="$(CC_BASE)"
+else
# The call to which here is to work around https://cmake.org/Bug/view.php?id=14366
CMAKE_COMMON += -DCMAKE_C_COMPILER="$$(which $(CC_BASE))"
+endif

This issue is a bit messy at the moment.
I would like to open a new issue when msys2 compiles normally.

@stahta01
Copy link
Contributor

Please see USE_BINARYBUILDER_BLASTRAMPOLINE = 0 fails
The upstream fix I submitted has been merged. The issue 48816 above contains a very small patch.

Tim S.

@vtjnash vtjnash closed this as completed May 23, 2023
@vtjnash
Copy link
Sponsor Member

vtjnash commented May 23, 2023

This seems rather old, and possibly outdated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:building Build system, or building Julia or its dependencies domain:ci Continuous integration system:windows Affects only Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants