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

phosg: support tests; phosg, resource_dasm: some fixes for older systems and PPC #18103

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions devel/phosg/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ github.tarball_from archive

# blacklisting to select C++20 capable compilers
compiler.blacklist-append {clang < 1300}
compiler.cxx_standard 2020
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barracuda156 your dedication to fixing ports on older systems is insane! Thank you for working on this 👍

Are you running bleeding-edge MacPorts on your machine? I think compiler.cxx_standard 2020 just sets the 2017 standard on stable MacPorts since support was only added 3 days ago (macports/macports-base@f23dca5).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harens Okay, but setting 2017 would make no difference now, but will have to be changed anyway later to 2020? Or do I miss something?
Alternatively we need to blacklist several versions of GCC, because otherwise they get picked, and build fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we need to blacklist several versions of GCC, because otherwise they get picked, and build fails.

I'm thinking more along those lines. Keep the cxx 20 but some other compilers might need to be blacklisted. From the mentioned commit:

-----------------------------------------------------------------------
#| C++ Standard |   Clang   |  Xcode Clang   |   Xcode   |     GCC     |
#|---------------------------------------------------------------------|
#| 2017 (C++17) |    5.0    |  1000.11.45.2  |   10.0    |      7      |
#| 2020 (C++20) |    14     |  1400.0.29.102 |   14.0    |     11      |


version 2023.03.04
revision 0
Expand All @@ -29,6 +30,24 @@ set python_version [string index ${pyver} 0][string range ${pyver} 2 end]

patchfiles CMakeLists-txt.diff

# https://github.com/fuzziqersoftware/phosg/pull/23
if {${os.platform} eq "darwin" && ${os.major} < 20} {
patchfiles-append 0001-Encoding.hh-define-__STDC_FORMAT_MACROS.patch \
0002-Image.hh-define-__darwin_ssize_t.patch \
0003-Network.cc-add-missing-cstring-header.patch \
0004-CMakeLists-fix-libatomic-for-macOS-ppc.patch \
0005-Filesystem-replacement-for-fmemopen.patch
}

depends_build-append port:python${python_version}

configure.args-append -DPYTHON_EXECUTABLE=${prefix}/bin/python${pyver}

pre-test {
# Test infrastructure uses /bin/ps, which is forbidden by sandboxing
append portsandbox_profile " (allow process-exec (literal \"/bin/ps\") (with no-profile))"
}

# Several tests fail on PPC: https://github.com/fuzziqersoftware/phosg/issues/24
test.run yes
test.cmd ctest
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
From af3d036dbc3c295a05789267db2002dafc170ad3 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Tue, 28 Mar 2023 00:46:39 +0700
Subject: [PATCH 1/5] Encoding.hh: define __STDC_FORMAT_MACROS

---
src/Encoding.hh | 1 +
1 file changed, 1 insertion(+)

diff --git a/src/Encoding.hh b/src/Encoding.hh
index 41343e9..2c1beee 100644
--- src/Encoding.hh
+++ src/Encoding.hh
@@ -1,5 +1,6 @@
#pragma once

+#define __STDC_FORMAT_MACROS
#include <stdint.h>
#include <inttypes.h>

23 changes: 23 additions & 0 deletions devel/phosg/files/0002-Image.hh-define-__darwin_ssize_t.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From b3fe3a1675100660da408f76f22bddfb1af4d9d8 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Tue, 28 Mar 2023 01:04:07 +0700
Subject: [PATCH 2/5] Image.hh: define __darwin_ssize_t

---
src/Image.hh | 3 +++
1 file changed, 3 insertions(+)

diff --git a/src/Image.hh b/src/Image.hh
index 76448cd..8aa9417 100644
--- src/Image.hh
+++ src/Image.hh
@@ -9,6 +9,9 @@

#include "Platform.hh"

+#ifdef __APPLE__
+typedef __darwin_ssize_t ssize_t;
+#endif

// an Image represents a drawing canvas. this class is fairly simple; it
// supports reading/writing individual pixels, drawing lines, and saving the
21 changes: 21 additions & 0 deletions devel/phosg/files/0003-Network.cc-add-missing-cstring-header.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
From adc9ad09c1fc4d2a1c452a0f27ecd9e0518c8649 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Tue, 28 Mar 2023 01:07:36 +0700
Subject: [PATCH 3/5] Network.cc: add missing cstring header

---
src/Network.cc | 1 +
1 file changed, 1 insertion(+)

diff --git a/src/Network.cc b/src/Network.cc
index 2e77df5..841868f 100644
--- src/Network.cc
+++ src/Network.cc
@@ -21,6 +21,7 @@

#include "Filesystem.hh"
#include "Strings.hh"
+#include <cstring>

using namespace std;

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From 83854a38491856c8fbaea9fe8bed04754ea6cafe Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Tue, 28 Mar 2023 01:36:33 +0700
Subject: [PATCH 4/5] CMakeLists: fix libatomic for macOS ppc

---
CMakeLists.txt | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ffe2368..053d92d 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -8,10 +8,12 @@ project(phosg)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
-if (MSVC)
+if(MSVC)
# Disabled warnings:
# 4458 = declaration of '%s' hides class member (I use this->x for members)
add_compile_options(/W4 /WX /wd4458)
+elseif(APPLE AND ${CMAKE_OSX_ARCHITECTURES} MATCHES "ppc|ppc64")
+ add_compile_options(-fpermissive -Wall -Wextra -Wno-strict-aliasing -Wno-unused-result -Wno-overflow)
else()
add_compile_options(-Wall -Wextra -Werror -Wno-strict-aliasing -Wno-unused-result -Wno-overflow)
endif()
@@ -31,10 +33,11 @@ add_library(phosg src/Encoding.cc src/Filesystem.cc src/Hash.cc src/Image.cc src
target_link_libraries(phosg pthread z)

# It seems that on some Linux variants (e.g. Raspbian) we also need -latomic,
-# but this library does not exist on others (e.g. Ubuntu) nor on macOS
+# but this library does not exist on others (e.g. Ubuntu).
+# Linking to libatomic is also needed on macOS ppc32. Use CMAKE_OSX_ARCHITECTURES to take care of Rosetta case.
message(STATUS "Target architecture is ${CMAKE_HOST_SYSTEM_PROCESSOR}")
string(FIND ${CMAKE_HOST_SYSTEM_PROCESSOR} "armv" IS_LINUX_ARMV)
-if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${IS_LINUX_ARMV} GREATER_EQUAL 0)
+if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${IS_LINUX_ARMV} GREATER_EQUAL 0 OR ${CMAKE_OSX_ARCHITECTURES} STREQUAL "ppc")
target_link_libraries(phosg atomic)
endif()

136 changes: 136 additions & 0 deletions devel/phosg/files/0005-Filesystem-replacement-for-fmemopen.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
From 0b9460cc026fe69ece6d6a96740bbc1d31c91d31 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Tue, 28 Mar 2023 01:24:42 +0700
Subject: [PATCH 5/5] Filesystem: replacement for fmemopen

---
src/Filesystem.cc | 94 +++++++++++++++++++++++++++++++++++++++++++++++
src/Filesystem.hh | 13 +++++++
2 files changed, 107 insertions(+)

diff --git a/src/Filesystem.cc b/src/Filesystem.cc
index 884128b..36d2764 100644
--- src/Filesystem.cc
+++ src/Filesystem.cc
@@ -678,3 +678,97 @@ unordered_map<int, short> Poll::poll(int timeout_ms) {
}
return ret;
}
+
+#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+#if MAC_OS_X_VERSION_MAX_ALLOWED < 101300
+// https://github.com/NimbusKit/memorymapping/blob/master/src/fmemopen.c
+
+#include <sys/mman.h>
+
+struct fmem {
+ size_t pos;
+ size_t size;
+ char *buffer;
+};
+typedef struct fmem fmem_t;
+
+static int readfn(void *handler, char *buf, int size) {
+ fmem_t *mem = handler;
+ size_t available = mem->size - mem->pos;
+
+ if (size > available) {
+ size = available;
+ }
+ memcpy(buf, mem->buffer + mem->pos, sizeof(char) * size);
+ mem->pos += size;
+
+ return size;
+}
+
+static int writefn(void *handler, const char *buf, int size) {
+ fmem_t *mem = handler;
+ size_t available = mem->size - mem->pos;
+
+ if (size > available) {
+ size = available;
+ }
+ memcpy(mem->buffer + mem->pos, buf, sizeof(char) * size);
+ mem->pos += size;
+
+ return size;
+}
+
+static fpos_t seekfn(void *handler, fpos_t offset, int whence) {
+ size_t pos;
+ fmem_t *mem = handler;
+
+ switch (whence) {
+ case SEEK_SET: {
+ if (offset >= 0) {
+ pos = (size_t)offset;
+ } else {
+ pos = 0;
+ }
+ break;
+ }
+ case SEEK_CUR: {
+ if (offset >= 0 || (size_t)(-offset) <= mem->pos) {
+ pos = mem->pos + (size_t)offset;
+ } else {
+ pos = 0;
+ }
+ break;
+ }
+ case SEEK_END: pos = mem->size + (size_t)offset; break;
+ default: return -1;
+ }
+
+ if (pos > mem->size) {
+ return -1;
+ }
+
+ mem->pos = pos;
+ return (fpos_t)pos;
+}
+
+static int closefn(void *handler) {
+ free(handler);
+ return 0;
+}
+
+FILE *fmemopen(void *buf, size_t size, const char *mode) {
+ // This data is released on fclose.
+ fmem_t* mem = (fmem_t *) malloc(sizeof(fmem_t));
+
+ // Zero-out the structure.
+ memset(mem, 0, sizeof(fmem_t));
+
+ mem->size = size;
+ mem->buffer = buf;
+
+ // funopen's man page: https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/funopen.3.html
+ return funopen(mem, readfn, writefn, seekfn, closefn);
+}
+#endif
+#endif
diff --git a/src/Filesystem.hh b/src/Filesystem.hh
index fcaf9b8..63ebbf2 100644
--- src/Filesystem.hh
+++ src/Filesystem.hh
@@ -20,6 +20,19 @@
#include <utility>
#include <vector>

+#ifdef __APPLE__
+ #include <AvailabilityMacros.h>
+ #if MAC_OS_X_VERSION_MAX_ALLOWED < 101300
+ // https://github.com/NimbusKit/memorymapping/blob/master/src/fmemopen.h
+ #if defined __cplusplus
+ extern "C" {
+ #endif
+ FILE *fmemopen(void *buf, size_t size, const char *mode);
+ #ifdef __cplusplus
+ }
+ #endif
+ #endif
+#endif


std::string basename(const std::string& filename);
5 changes: 5 additions & 0 deletions devel/resource_dasm/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ PortSystem 1.0
PortGroup cmake 1.1
PortGroup github 1.0
PortGroup compiler_blacklist_versions 1.0
PortGroup legacysupport 1.1

# MAP_ANONYMOUS
legacysupport.newest_darwin_requires_legacy 14

github.setup fuzziqersoftware resource_dasm 46ad32e
github.tarball_from archive

# blacklisting to select C++20 capable compilers
compiler.blacklist-append {clang < 1300}
compiler.cxx_standard 2020

version 2023.03.15
revision 0
Expand Down