From 5341b0e95de5fb3d05b34cd10f31784dec3bfba3 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Sun, 24 Nov 2024 08:01:10 +0000 Subject: [PATCH] (stdlib) Fix OpenBSD build issues With these changes in place, the `perlang_cli` and `stdlib` (C++) projects now compile successfully on OpenBSD 7.6. These changes should also make our eventual porting effort to FreeBSD and macOS simpler, both of which use the LLVM libc++ as their C++ standard library. Related issue: https://gitlab.perlang.org/perlang/perlang/-/issues/503 https://gitlab.perlang.org/perlang/perlang/-/merge_requests/564 --- .gitlab-ci.yml | 6 +++--- Makefile | 18 ++++++++++++++---- release-notes/v0.6.0.md | 2 ++ src/perlang_cli/src/Makefile | 15 +++++++++++++-- src/stdlib/src/int_array.cc | 1 + src/stdlib/src/int_array.h | 2 ++ src/stdlib/src/io/file.cc | 1 + src/stdlib/src/string_array.cc | 1 + 8 files changed, 37 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 648ef6a0..23139ceb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,9 +37,9 @@ build-netbsd: - netbsd script: - - make perlang_cli - - make stdlib - - make test-stdlib EXTRA_CATCH_REPORTER="--reporter JUnit::out=native-stdlib-junit-log.xml"; + - gmake perlang_cli + - gmake stdlib + - gmake test-stdlib EXTRA_CATCH_REPORTER="--reporter JUnit::out=native-stdlib-junit-log.xml"; artifacts: when: always paths: diff --git a/Makefile b/Makefile index c5454976..f41d383d 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,18 @@ RELEASE_PERLANG=$(RELEASE_PERLANG_DIRECTORY)/perlang # --suppressions because .NET runtime has some existing Valgrind issues: https://github.com/dotnet/runtime/issues/52872 VALGRIND=DOTNET_GCHeapHardLimit=C800000 valgrind --undef-value-errors=no --error-exitcode=1 --show-leak-kinds=all --leak-check=full --suppressions=scripts/valgrind-suppressions.txt -# Enable fail-fast in case of errors -SHELL=/bin/bash -e -o pipefail +UNAME := $(shell uname -s) + +# bash is located in different directories on different systems. Also, enable fail-fast in case of errors. +ifeq ($(UNAME), Linux) + SHELL := /bin/bash -e -o pipefail +else ifeq ($(UNAME), NetBSD) + SHELL := /usr/pkg/bin/bash -e -o pipefail +else ifeq ($(UNAME), OpenBSD) + SHELL := /usr/local/bin/bash -e -o pipefail +else + $(error Unsupported operating system $(UNAME) encountered) +endif CLANGPP=clang++-14 @@ -122,7 +132,7 @@ stdlib: # perlang_cli depends on stdlib, so it must be built before this can be successfully built perlang_cli: stdlib # Precompile the Perlang files to C++ if needed, so that they can be picked up by the CMake build - cd src/perlang_cli/src && make + cd src/perlang_cli/src && $(MAKE) cd src/perlang_cli && mkdir -p out && cd out && cmake -DCMAKE_INSTALL_PREFIX:PATH=../../../lib/perlang_cli -G "Unix Makefiles" .. && make perlang_cli install @@ -130,7 +140,7 @@ perlang_cli: stdlib # are normally committed to git. This makes it easy to regenerate them from the # Perlang sources. perlang_cli_clean: - cd src/perlang_cli/src && make clean + cd src/perlang_cli/src && $(MAKE) clean cd src/perlang_cli && rm -rf out perlang_cli_install_debug: perlang_cli diff --git a/release-notes/v0.6.0.md b/release-notes/v0.6.0.md index 3f5aacfa..8206d507 100644 --- a/release-notes/v0.6.0.md +++ b/release-notes/v0.6.0.md @@ -48,6 +48,7 @@ - Ensure `ASCIIString`s contain ASCII content only [[!557][557]] - Fix memory leak in tests [[!558][558]] - Support comparison between `UTF8String` and `ASCIIString` [[!560][560]] +- Fix OpenBSD build issues [[!564][564]] #### CI - Add `dotnet test` CI job [[!499][499]] @@ -157,3 +158,4 @@ [560]: https://gitlab.perlang.org/perlang/perlang/merge_requests/560 [561]: https://gitlab.perlang.org/perlang/perlang/merge_requests/561 [562]: https://gitlab.perlang.org/perlang/perlang/merge_requests/562 +[564]: https://gitlab.perlang.org/perlang/perlang/merge_requests/564 diff --git a/src/perlang_cli/src/Makefile b/src/perlang_cli/src/Makefile index 70db77ab..00e75f91 100644 --- a/src/perlang_cli/src/Makefile +++ b/src/perlang_cli/src/Makefile @@ -1,6 +1,17 @@ .PHONY: all clean -SHELL := /bin/bash -e -o pipefail +UNAME := $(shell uname -s) + +# bash is located in different directories on different systems. Also, enable fail-fast in case of errors. +ifeq ($(UNAME), Linux) + SHELL := /bin/bash -e -o pipefail +else ifeq ($(UNAME), NetBSD) + SHELL := /usr/pkg/bin/bash -e -o pipefail +else ifeq ($(UNAME), OpenBSD) + SHELL := /usr/local/bin/bash -e -o pipefail +else + $(error Unsupported operating system $(UNAME) encountered) +endif CPP_SOURCES = perlang_cli_preprocessed.cc @@ -24,7 +35,7 @@ perlang_cli_preprocessed.cc: perlang_cli.cc -e 's/##BUILD_TIMESTAMP##/$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')/g' \ -e 's/##BUILD_USER##/$(shell whoami)/g' \ -e 's/##BUILD_HOST##/$(shell hostname)/g' \ - $< > $@ + perlang_cli.cc > $@ # Note: this deliberately uses the Perlang installed using install-latest-snapshot, to avoid depending on a Perlang # toolchain built in this repo (which depends on perlang_cli.so, built using these rules). The latest snapshot is diff --git a/src/stdlib/src/int_array.cc b/src/stdlib/src/int_array.cc index 8082f1ce..3e54176a 100644 --- a/src/stdlib/src/int_array.cc +++ b/src/stdlib/src/int_array.cc @@ -1,5 +1,6 @@ #include #include +#include #include "int_array.h" diff --git a/src/stdlib/src/int_array.h b/src/stdlib/src/int_array.h index 03781934..124289d3 100644 --- a/src/stdlib/src/int_array.h +++ b/src/stdlib/src/int_array.h @@ -1,3 +1,5 @@ +#include + #pragma once namespace perlang diff --git a/src/stdlib/src/io/file.cc b/src/stdlib/src/io/file.cc index 6b57004d..83c88812 100644 --- a/src/stdlib/src/io/file.cc +++ b/src/stdlib/src/io/file.cc @@ -1,5 +1,6 @@ #include #include +#include #include "io/file.h" #include "utf8_string.h" diff --git a/src/stdlib/src/string_array.cc b/src/stdlib/src/string_array.cc index ea0cfda7..d74e6dd2 100644 --- a/src/stdlib/src/string_array.cc +++ b/src/stdlib/src/string_array.cc @@ -1,5 +1,6 @@ #include #include +#include #include "ascii_string.h" #include "string_array.h"