Skip to content

Commit

Permalink
(stdlib) Fix OpenBSD build issues
Browse files Browse the repository at this point in the history
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
  • Loading branch information
perlun committed Nov 24, 2024
1 parent 34c1b87 commit 5341b0e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -122,15 +132,15 @@ 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

# Note that this removes all auto-generated files, including the C++ files which
# 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
Expand Down
2 changes: 2 additions & 0 deletions release-notes/v0.6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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
15 changes: 13 additions & 2 deletions src/perlang_cli/src/Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/stdlib/src/int_array.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <memory.h>
#include <stdexcept>
#include <string>

#include "int_array.h"

Expand Down
2 changes: 2 additions & 0 deletions src/stdlib/src/int_array.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <initializer_list>

#pragma once

namespace perlang
Expand Down
1 change: 1 addition & 0 deletions src/stdlib/src/io/file.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cstdio>
#include <stdexcept>
#include <string>

#include "io/file.h"
#include "utf8_string.h"
Expand Down
1 change: 1 addition & 0 deletions src/stdlib/src/string_array.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <memory>
#include <stdexcept>
#include <string>

#include "ascii_string.h"
#include "string_array.h"
Expand Down

0 comments on commit 5341b0e

Please sign in to comment.