Skip to content

Commit

Permalink
Merge pull request #559 from Chilledheart/build_add_mingw_allow_xp_su…
Browse files Browse the repository at this point in the history
…pport

Build add mingw allow xp support
  • Loading branch information
Chilledheart authored Dec 21, 2023
2 parents 8ffd330 + c61dc41 commit 1992d40
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 14 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/compiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ env:
GOPROXY: direct
jobs:
win-compiler-compatible-2022:
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
arch: [x64, x86]
crt-linkage: [static]
build_type: [Debug, Release]
runs-on: windows-2022
env:
BUILD_TYPE: '${{ matrix.build_type }}'
defaults:
Expand Down Expand Up @@ -123,12 +123,14 @@ jobs:
yass_test -logtostderr -v 1 --gtest_shuffle --gtest_repeat=10 --gtest_throw_on_failure --proxy_type socks5h --ipv6_mode
yass_test -logtostderr -v 1 --gtest_shuffle --gtest_repeat=10 --gtest_throw_on_failure --proxy_type http --ipv6_mode
mingw64-compiler-compatible-crosscompiling:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
arch: [i686, x86_64, aarch64]
build_type: [Debug, Release]
runs-on: ubuntu-20.04
env:
BUILD_TYPE: '${{ matrix.build_type }}'
steps:
- uses: actions/checkout@v4
- name: Checkout with shallow submodules
Expand Down Expand Up @@ -199,7 +201,6 @@ jobs:
- name: Populate llvm-mingw
run: |
sudo tar -C /opt -xvf llvm-mingw-20230614-ucrt-ubuntu-20.04-x86_64.tar.xz
sudo ln -sf libclang_rt.builtins-i386.a /opt/llvm-mingw-20230614-ucrt-ubuntu-20.04-x86_64/lib/clang/16/lib/windows/libclang_rt.builtins-i686.a
- name: Populate depedencies
run: |
sudo apt-get update -qq
Expand All @@ -208,7 +209,7 @@ jobs:
sudo apt-get install -y python3-jsonschema python3-jinja2
- name: Build
run: |
./tools/build --variant gui --arch ${{ matrix.arch }} --system mingw -build-test -cmake-build-type ${{ matrix.build_type }} \
./tools/build --variant gui --arch ${{ matrix.arch }} --system mingw -build-test \
--clang-path /opt/llvm-mingw-20230614-ucrt-ubuntu-20.04-x86_64 -nc
- name: Populate depedencies (Tests-i686)
if: ${{ matrix.arch == 'i686' }}
Expand Down Expand Up @@ -243,13 +244,13 @@ jobs:
wine yass_test.exe -logtostderr -v 1 --gtest_shuffle --gtest_repeat=10 --gtest_throw_on_failure --proxy_type socks5h --ipv6_mode
wine yass_test.exe -logtostderr -v 1 --gtest_shuffle --gtest_repeat=10 --gtest_throw_on_failure --proxy_type http --ipv6_mode
linux-compiler-compatible:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
compiler: [clang]
build_type: [Debug, Release]
cxxruntime: [libc++]
runs-on: ubuntu-22.04
env:
BUILD_TYPE: '${{ matrix.build_type }}'
steps:
Expand Down
5 changes: 3 additions & 2 deletions cmake/platforms/MinGW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ set(CMAKE_C_COMPILER_RANLIB "${LLVM_SYSROOT}/bin/llvm-ranlib")
set(CMAKE_CXX_COMPILER_RANLIB "${LLVM_SYSROOT}/bin/llvm-ranlib")
# disabled because it is missing from binary
# set(CMAKE_RC_COMPILER "${LLVM_SYSROOT}/bin/llvm-rc")
set(CMAKE_RC_COMPILER "${LLVM_SYSROOT}/bin/${GCC_TARGET}-windres")
set(CMAKE_RC_COMPILER "${MINGW_SYSROOT}/bin/${GCC_TARGET}-windres")
set(CMAKE_RC_COMPILER_ARG1 "--codepage 65001")

set(CMAKE_SYSROOT "${LLVM_SYSROOT}/${GCC_TARGET}" CACHE STRING "")
set(CMAKE_SYSROOT "${MINGW_SYSROOT}/${GCC_TARGET}" CACHE STRING "")

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH ${LLVM_SYSROOT}/${GCC_TARGET})
Expand Down
21 changes: 15 additions & 6 deletions third_party/libc++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,21 @@ else()
)
endif()
elseif (MINGW AND MINGW_MSVCRT100)
set(libcxx_PUBLIC_LIBRARIES
${libcxx_PUBLIC_LIBRARIES}
mingw32 gcc_eh gcc moldname mingwex msvcr100
advapi32 shell32 user32 kernel32
mingw32 gcc_eh gcc moldname mingwex msvcr100 kernel32
)
if (MINGW_COMPILER_RT)
set(libcxx_PUBLIC_LIBRARIES
${libcxx_PUBLIC_LIBRARIES}
${CMAKE_SYSROOT}/lib/libmingw32.a ${MINGW_COMPILER_RT} unwind moldname mingwex msvcr100
advapi32 shell32 user32 kernel32
${CMAKE_SYSROOT}/lib/libmingw32.a ${MINGW_COMPILER_RT} unwind moldname mingwex msvcr100 kernel32
)
else()
set(libcxx_PUBLIC_LIBRARIES
${libcxx_PUBLIC_LIBRARIES}
mingw32 gcc_eh gcc moldname mingwex msvcr100
advapi32 shell32 user32 kernel32
mingw32 gcc_eh gcc moldname mingwex msvcr100 kernel32
)
endif()
endif()
endif()
endif()
Expand Down
65 changes: 64 additions & 1 deletion tools/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ var archFlag string

var variantFlag string

var mingwDir string
var mingwAllowXpFlag bool

var androidAppAbi string
var androidAbiTarget string
var androidApiLevel int
Expand Down Expand Up @@ -174,6 +177,9 @@ func InitFlag() {

flag.StringVar(&variantFlag, "variant", "gui", "Specify variant, available: gui, cli, server")

flag.StringVar(&mingwDir, "mingw-dir", "", "MinGW Dir Path")
flag.BoolVar(&mingwAllowXpFlag, "mingw-allow-xp", false, "Enable Windows XP Build")

flag.IntVar(&androidApiLevel, "android-api", 24, "Select Android API Level")
flag.StringVar(&androidSdkDir, "android-sdk-dir", getEnv("ANDROID_SDK_ROOT", ""), "Android SDK Home Path")
flag.StringVar(&androidNdkDir, "android-ndk-dir", getEnv("ANDROID_NDK_ROOT", "../third_party/android_toolchain"), "Android NDK Home Path")
Expand Down Expand Up @@ -275,6 +281,12 @@ func prebuildFindSourceDirectory() {
osSuffix = "-winxp"
}
buildDir = fmt.Sprintf("build-msvc%s-%s-%s", osSuffix, msvcTargetArchFlag, msvcCrtLinkageFlag)
} else if systemNameFlag == "mingw" {
osSuffix := ""
if mingwAllowXpFlag {
osSuffix = "-winxp"
}
buildDir = fmt.Sprintf("build-%s%s-%s", systemNameFlag, osSuffix, archFlag)
} else if systemNameFlag == "freebsd" {
buildDir = fmt.Sprintf("build-%s%d-%s", systemNameFlag, freebsdAbiFlag, archFlag)
} else if systemNameFlag == "android" {
Expand Down Expand Up @@ -443,6 +455,25 @@ func getGNUTargetTypeAndArch(arch string, subsystem string) (string, string) {
return "", ""
}

func getLLVMVersion() string {
entries, err := os.ReadDir(filepath.Join(clangPath, "lib", "clang"))
if err != nil {
glog.Fatalf("%v", err)
}
var llvm_version string
for _, entry := range entries {
llvm_version = entry.Name()
}
if llvm_version == "" {
glog.Fatalf("toolchain not found")
}
return llvm_version
}

func getAndFixMinGWLibunwind(mingwDir string) {
getAndFixLibunwind(fmt.Sprintf("%s/lib/clang/16/lib/windows", mingwDir), "windows")
}

func getAndFixAndroidLibunwind(ndkDir string) {
getAndFixLibunwind(fmt.Sprintf("%s/toolchains/llvm/prebuilt/%s-x86_64/lib64/clang/14.0.7/lib/linux", ndkDir, runtime.GOOS), "linux")
}
Expand Down Expand Up @@ -785,7 +816,14 @@ func buildStageGenerateBuildScript() {
}

if systemNameFlag == "mingw" {
glog.Infof("Using llvm-mingw dir %s", clangPath);
if (mingwDir != "") {
glog.Infof("Using llvm-mingw dir %s", mingwDir);
glog.Infof("Using clang dir %s", clangPath);
} else {
mingwDir = clangPath
glog.Infof("Using llvm-mingw dir %s", clangPath);
glog.Infof("Using clang inside llvm-mingw dir %s", mingwDir);
}
cmakeArgs = append(cmakeArgs, fmt.Sprintf("-DCROSS_TOOLCHAIN_FLAGS_TOOLCHAIN_FILE=%s/Native.cmake", buildDir))

ccCompiler := os.Getenv("CC")
Expand All @@ -800,8 +838,27 @@ func buildStageGenerateBuildScript() {
targetTriple, targetAbi := getMinGWTargetAndAppAbi(archFlag)
cmakeArgs = append(cmakeArgs, fmt.Sprintf("-DCMAKE_TOOLCHAIN_FILE=%s/../cmake/platforms/MinGW.cmake", buildDir))
cmakeArgs = append(cmakeArgs, fmt.Sprintf("-DLLVM_SYSROOT=%s", clangPath))
cmakeArgs = append(cmakeArgs, fmt.Sprintf("-DMINGW_SYSROOT=%s", mingwDir))
cmakeArgs = append(cmakeArgs, fmt.Sprintf("-DGCC_SYSTEM_PROCESSOR=%s", targetAbi))
cmakeArgs = append(cmakeArgs, fmt.Sprintf("-DGCC_TARGET=%s", targetTriple))

if mingwAllowXpFlag {
cmakeArgs = append(cmakeArgs, "-DALLOW_XP=ON")
cmakeArgs = append(cmakeArgs, "-DMINGW_MSVCRT100=ON")
cmakeArgs = append(cmakeArgs, "-DMINGW_WORKAROUND=ON")
llvm_version := getLLVMVersion()
clang_rt_suffix := targetAbi
if (targetAbi == "i686") {
clang_rt_suffix = "i386"
}
cmakeArgs = append(cmakeArgs, fmt.Sprintf("-DMINGW_COMPILER_RT=%s/lib/clang/%s/lib/windows/libclang_rt.builtins-%s.a", clangPath, llvm_version, clang_rt_suffix))
} else {
cmakeArgs = append(cmakeArgs, "-DALLOW_XP=OFF")
}

if (mingwDir != clangPath) {
getAndFixMinGWLibunwind(mingwDir)
}
}

if systemNameFlag == "ios" {
Expand Down Expand Up @@ -1486,6 +1543,12 @@ func postStateArchives() map[string][]string {
osName = "winxp"
}
archiveFormat = fmt.Sprintf("%%s-%s-release-%s-%s-%s%%s%%s", osName, msvcTargetArchFlag, msvcCrtLinkageFlag, tag)
} else if systemNameFlag == "mingw" {
osName := "mingw"
if mingwAllowXpFlag {
osName = "mingw-winxp"
}
archiveFormat = fmt.Sprintf("%%s-%s-release-%s-%s%%s%%s", osName, archFlag, tag)
} else if systemNameFlag == "darwin" {
osName := "macos"
arch := archFlag
Expand Down

0 comments on commit 1992d40

Please sign in to comment.