Hi, The following diff updates lang/zig to 0.8.1 version.
But I changed the way the port is done. Previously I took upstream tarball from zig-bootstrap repository which carry some all it is need to build zig (plain llvm 12 + clang + lld). The llvm part was slightly patched to minimal to be able to build on OpenBSD. Here, I am using zig repository, and I also fetch llvm 12 from github, using mortimer branch, with all OpenBSD specific patches. It also helps mirrors as llvm-12 tarball shouldn't change too often. I intent to follow zig 0.8.x branch and update the port regulary to 0.8.2preXX . Any comments or OK ? -- Sebastien Marie Index: Makefile =================================================================== RCS file: /cvs/ports/lang/zig/Makefile,v retrieving revision 1.8 diff -u -p -r1.8 Makefile --- Makefile 26 Aug 2021 04:37:15 -0000 1.8 +++ Makefile 7 Sep 2021 15:22:48 -0000 @@ -11,11 +11,15 @@ DPB_PROPERTIES = parallel COMMENT = zig compiler and toolchain -DISTNAME = zig-0.8.1pre29 +DISTNAME = zig-0.8.1 -GH_ACCOUNT = ziglang -GH_PROJECT = zig-bootstrap -GH_COMMIT = ffc05c41b275f2c3c10038707df3d3649713f7af +# see https://github.com/ziglang/zig/tree/0.8.x +ZIG_VERSION = 0.8.1 +ZIG_COMMIT = 12828c09d66873f1626d21c898117969764f3a4f + +# see https://github.com/mordak/llvm-project/tree/openbsd-release/12.x +LLVM_VERSION = 12.x +LLVM_COMMIT = d01534d1b1a68a370db6e79ea0ea03a63cf778d7 CATEGORIES = lang @@ -28,6 +32,12 @@ PERMIT_PACKAGE = Yes WANTLIB = ${COMPILER_LIBCXX} c m +MASTER_SITES = https://github.com/ziglang/zig/archive/ +MASTER_SITES0 = https://github.com/mordak/llvm-project/archive/ + +DISTFILES = zig-${ZIG_VERSION}-${ZIG_COMMIT:C/(........).*/\1/}${EXTRACT_SUFX}{${ZIG_COMMIT}${EXTRACT_SUFX}} \ + llvm-project-${LLVM_VERSION}-${LLVM_COMMIT:C/(........).*/\1/}${EXTRACT_SUFX}{${LLVM_COMMIT}${EXTRACT_SUFX}}:0 + # C++11 COMPILER = base-clang ports-gcc @@ -46,7 +56,13 @@ MAKE_ENV += CXXFLAGS="${CXXFLAGS}" \ # command to build/install/test BUILDCMD = cd ${WRKBUILD} && exec ${SETENV} ${MAKE_ENV} \ - sh "${.CURDIR}/files/build.sh" + sh "${.CURDIR}/files/build.sh" \ + "${ZIG_VERSION}+${ZIG_COMMIT:C/(.........).*/\1/}" + +post-extract: + mkdir -p ${WRKSRC} + mv ${WRKDIR}/zig-${ZIG_COMMIT} ${WRKSRC}/zig + mv ${WRKDIR}/llvm-project-${LLVM_COMMIT} ${WRKSRC}/llvm-project pre-configure: @ln -fs ${MODPY_BIN} ${WRKDIR}/bin/python Index: distinfo =================================================================== RCS file: /cvs/ports/lang/zig/distinfo,v retrieving revision 1.5 diff -u -p -r1.5 distinfo --- distinfo 26 Aug 2021 04:37:15 -0000 1.5 +++ distinfo 7 Sep 2021 15:22:48 -0000 @@ -1,2 +1,4 @@ -SHA256 (zig-0.8.1pre29-ffc05c41.tar.gz) = VjJJrqW0F4ZafFdbv/HFQkGug6zrtO713KRVSAtnaBA= -SIZE (zig-0.8.1pre29-ffc05c41.tar.gz) = 62572302 +SHA256 (llvm-project-12.x-d01534d1.tar.gz) = 6t82ae1rQtyCw5ZzfDtpVWhl0y3/g+ROzo+wS3LSRrA= +SHA256 (zig-0.8.1-12828c09.tar.gz) = Yg44RYoZLzn3G0d8RzWlmGypzYEFFWYlDEr1fokTxWk= +SIZE (llvm-project-12.x-d01534d1.tar.gz) = 134366334 +SIZE (zig-0.8.1-12828c09.tar.gz) = 19661360 Index: files/build.sh =================================================================== RCS file: /cvs/ports/lang/zig/files/build.sh,v retrieving revision 1.3 diff -u -p -r1.3 build.sh --- files/build.sh 24 Apr 2021 13:59:21 -0000 1.3 +++ files/build.sh 7 Sep 2021 15:22:48 -0000 @@ -8,17 +8,14 @@ LLVMINST="${WRKBUILD}/llvm-install" ZIG1BUILD="${WRKBUILD}/zig-stage1" ZIG2BUILD="${WRKBUILD}/zig-stage2" -# extract zig version -TARGET_VERSION=$(sed -ne 's/^ZIG_VERSION="\([^"]*\)"$/\1/p' < "${WRKSRC}/build") - # disable some llvm protections in the llvm compiler to regain performance case $(machine) in -aarch64) CXXFLAGS="-fno-ret-protector ${CXXFLAGS:-}" ;; -amd64) CXXFLAGS="-fno-ret-protector -mno-retpoline ${CXXFLAGS:-}" ;; -i386) CXXFLAGS="-fno-ret-protector -mno-retpoline ${CXXFLAGS:-}" ;; -mips64) CXXFLAGS="-fno-ret-protector -fomit-frame-pointer ${CXXFLAGS:-}" ;; -mips64el) CXXFLAGS="-fno-ret-protector -fomit-frame-pointer ${CXXFLAGS:-}" ;; -powerpc) CXXFLAGS="-fno-ret-protector ${CXXFLAGS:-}" +aarch64) XFLAGS="-fno-ret-protector" ;; +amd64) XFLAGS="-fno-ret-protector -mno-retpoline" ;; +i386) XFLAGS="-fno-ret-protector -mno-retpoline" ;; +mips64) XFLAGS="-fno-ret-protector -fomit-frame-pointer" ;; +mips64el) XFLAGS="-fno-ret-protector -fomit-frame-pointer" ;; +powerpc) XFLAGS="-fno-ret-protector" CMAKE_SHARED_LINKER_FLAGS="-Wl,-relax" ;; esac @@ -28,8 +25,10 @@ llvm_configure() { [ ! -d "${LLVMBUILD}" ] && mkdir "${LLVMBUILD}" "${LLVMINST}" cd "${LLVMBUILD}" - env CXXFLAGS="${CXXFLAGS:-}" VERBOSE=1 MODCMAKE_PORT_BUILD=yes \ - cmake -GNinja "${WRKSRC}/llvm" \ + env CXXFLAGS="${XFLAGS:-} ${CXXFLAGS:-}" \ + VERBOSE=1 \ + MODCMAKE_PORT_BUILD=yes \ + cmake -GNinja "${WRKSRC}/llvm-project/llvm" \ -DLLVM_ENABLE_PROJECTS="clang;lld" \ -DLLVM_ENABLE_LIBXML2=OFF \ -DLLVM_ENABLE_TERMINFO=OFF \ @@ -67,7 +66,10 @@ zig1_configure() { # configure zig stage1 cd "${ZIG1BUILD}" - env CXXFLAGS="${CXXFLAGS:-}" VERBOSE=1 MODCMAKE_PORT_BUILD=yes \ + env CFLAGS="${XFLAGS:-} ${CFLAGS:-}" \ + CXXFLAGS="${XFLAGS:-} ${CXXFLAGS:-}" \ + VERBOSE=1 \ + MODCMAKE_PORT_BUILD=yes \ cmake -GNinja "${WRKSRC}/zig" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_COMPILER="${CC:-cc}" \ @@ -149,11 +151,19 @@ zig_test() { --verbose-link } -case "${1:-help}" in -help) - echo "$0 [build|install|test]" - exit 1 - ;; +usage() { + echo "$0 version [build|install|test]" + exit 1 +} + +if [ $# -ne 2 ]; then + usage +fi + +# set zig version +TARGET_VERSION=${1} + +case "${2}" in build) llvm_configure llvm_build @@ -168,5 +178,8 @@ test) zig2_build # zig testsuite zig_test + ;; +*) + usage ;; esac Index: patches/patch-lld_ELF_DriverUtils_cpp =================================================================== RCS file: patches/patch-lld_ELF_DriverUtils_cpp diff -N patches/patch-lld_ELF_DriverUtils_cpp --- patches/patch-lld_ELF_DriverUtils_cpp 24 Apr 2021 13:59:21 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,43 +0,0 @@ -$OpenBSD: patch-lld_ELF_DriverUtils_cpp,v 1.2 2021/04/24 13:59:21 semarie Exp $ - -Index: lld/ELF/DriverUtils.cpp ---- lld/ELF/DriverUtils.cpp.orig -+++ lld/ELF/DriverUtils.cpp -@@ -231,9 +231,36 @@ Optional<std::string> elf::findFromSearchPaths(StringR - // search paths. - Optional<std::string> elf::searchLibraryBaseName(StringRef name) { - for (StringRef dir : config->searchPaths) { -- if (!config->isStatic) -+ if (!config->isStatic) { - if (Optional<std::string> s = findFile(dir, "lib" + name + ".so")) - return s; -+ -+ // Handle OpenBSD-style maj/min shlib scheme -+ llvm::SmallString<128> Scratch; -+ const StringRef LibName = ("lib" + name + ".so.").toStringRef(Scratch); -+ int MaxMaj = -1, MaxMin = -1; -+ std::error_code EC; -+ for (fs::directory_iterator LI(dir, EC), LE; -+ LI != LE; LI = LI.increment(EC)) { -+ StringRef FilePath = LI->path(); -+ StringRef FileName = path::filename(FilePath); -+ if (!(FileName.startswith(LibName))) -+ continue; -+ std::pair<StringRef, StringRef> MajMin = -+ FileName.substr(LibName.size()).split('.'); -+ int Maj, Min; -+ if (MajMin.first.getAsInteger(10, Maj) || Maj < 0) -+ continue; -+ if (MajMin.second.getAsInteger(10, Min) || Min < 0) -+ continue; -+ if (Maj > MaxMaj) -+ MaxMaj = Maj, MaxMin = Min; -+ if (MaxMaj == Maj && Min > MaxMin) -+ MaxMin = Min; -+ } -+ if (MaxMaj >= 0) -+ return findFile(dir, LibName + Twine(MaxMaj) + "." + Twine(MaxMin)); -+ } - if (Optional<std::string> s = findFile(dir, "lib" + name + ".a")) - return s; - } Index: patches/patch-lld_ELF_Driver_cpp =================================================================== RCS file: patches/patch-lld_ELF_Driver_cpp diff -N patches/patch-lld_ELF_Driver_cpp --- patches/patch-lld_ELF_Driver_cpp 24 Apr 2021 13:59:21 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,28 +0,0 @@ -$OpenBSD: patch-lld_ELF_Driver_cpp,v 1.2 2021/04/24 13:59:21 semarie Exp $ - -Index: lld/ELF/Driver.cpp ---- lld/ELF/Driver.cpp.orig -+++ lld/ELF/Driver.cpp -@@ -666,6 +666,9 @@ static bool isOutputFormatBinary(opt::InputArgList &ar - } - - static DiscardPolicy getDiscard(opt::InputArgList &args) { -+ if (args.hasArg(OPT_relocatable)) -+ return DiscardPolicy::None; -+ - auto *arg = - args.getLastArg(OPT_discard_all, OPT_discard_locals, OPT_discard_none); - if (!arg) -@@ -1042,7 +1045,12 @@ static void readConfigs(opt::InputArgList &args) { - config->optimize = args::getInteger(args, OPT_O, 1); - config->orphanHandling = getOrphanHandling(args); - config->outputFile = args.getLastArgValue(OPT_o); -+#ifdef __OpenBSD__ -+ config->pie = args.hasFlag(OPT_pie, OPT_no_pie, -+ !args.hasArg(OPT_shared) && !args.hasArg(OPT_relocatable)); -+#else - config->pie = args.hasFlag(OPT_pie, OPT_no_pie, false); -+#endif - config->printIcfSections = - args.hasFlag(OPT_print_icf_sections, OPT_no_print_icf_sections, false); - config->printGcSections = Index: patches/patch-llvm_cmake_modules_GetLibraryName_cmake =================================================================== RCS file: patches/patch-llvm_cmake_modules_GetLibraryName_cmake diff -N patches/patch-llvm_cmake_modules_GetLibraryName_cmake --- patches/patch-llvm_cmake_modules_GetLibraryName_cmake 24 Apr 2021 13:59:21 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,14 +0,0 @@ -$OpenBSD: patch-llvm_cmake_modules_GetLibraryName_cmake,v 1.1 2021/04/24 13:59:21 semarie Exp $ - -Index: llvm/cmake/modules/GetLibraryName.cmake ---- llvm/cmake/modules/GetLibraryName.cmake.orig -+++ llvm/cmake/modules/GetLibraryName.cmake -@@ -2,7 +2,7 @@ - function(get_library_name path name) - get_filename_component(path ${path} NAME) - set(prefixes ${CMAKE_FIND_LIBRARY_PREFIXES}) -- set(suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES}) -+ set(suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES} ".so.[0-9]+.[0-9]+") - list(FILTER prefixes EXCLUDE REGEX "^\\s*$") - list(FILTER suffixes EXCLUDE REGEX "^\\s*$") - if(prefixes) Index: pkg/PLIST =================================================================== RCS file: /cvs/ports/lang/zig/pkg/PLIST,v retrieving revision 1.5 diff -u -p -r1.5 PLIST --- pkg/PLIST 26 Aug 2021 04:37:15 -0000 1.5 +++ pkg/PLIST 7 Sep 2021 15:22:59 -0000 @@ -6404,6 +6404,7 @@ lib/zig/libc/mingw/lib-common/d3d12.def lib/zig/libc/mingw/lib-common/d3d9.def lib/zig/libc/mingw/lib-common/d3dcompiler_47.def lib/zig/libc/mingw/lib-common/davclnt.def +lib/zig/libc/mingw/lib-common/dbghelp.def lib/zig/libc/mingw/lib-common/dcomp.def lib/zig/libc/mingw/lib-common/ddraw.def lib/zig/libc/mingw/lib-common/dfscli.def @@ -6466,6 +6467,7 @@ lib/zig/libc/mingw/lib-common/netutils.d lib/zig/libc/mingw/lib-common/normaliz.def lib/zig/libc/mingw/lib-common/ntdll.def.in lib/zig/libc/mingw/lib-common/ntdsapi.def +lib/zig/libc/mingw/lib-common/odbc32.def lib/zig/libc/mingw/lib-common/ole32.def.in lib/zig/libc/mingw/lib-common/oleacc.def lib/zig/libc/mingw/lib-common/oleaut32.def.in @@ -6594,6 +6596,7 @@ lib/zig/libc/mingw/lib32/d3d12.def lib/zig/libc/mingw/lib32/d3d9.def lib/zig/libc/mingw/lib32/d3dcompiler_47.def lib/zig/libc/mingw/lib32/davclnt.def +lib/zig/libc/mingw/lib32/dbghelp.def lib/zig/libc/mingw/lib32/dcomp.def lib/zig/libc/mingw/lib32/ddraw.def lib/zig/libc/mingw/lib32/dfscli.def @@ -6657,6 +6660,7 @@ lib/zig/libc/mingw/lib32/newdev.def lib/zig/libc/mingw/lib32/normaliz.def lib/zig/libc/mingw/lib32/ntdll.def lib/zig/libc/mingw/lib32/ntdsapi.def +lib/zig/libc/mingw/lib32/odbc32.def lib/zig/libc/mingw/lib32/ole32.def lib/zig/libc/mingw/lib32/oleacc.def lib/zig/libc/mingw/lib32/oleaut32.def @@ -6749,6 +6753,7 @@ lib/zig/libc/mingw/lib64/msctfmonitor.de lib/zig/libc/mingw/lib64/msvfw32.def lib/zig/libc/mingw/lib64/newdev.def lib/zig/libc/mingw/lib64/ntlanman.def +lib/zig/libc/mingw/lib64/odbc32gt.def lib/zig/libc/mingw/lib64/opengl32.def lib/zig/libc/mingw/lib64/pdh.def lib/zig/libc/mingw/lib64/quartz.def