Skip to content

Commit 446dde5

Browse files
authored
Merge pull request #60 from zonkyio/#52-rosetta2-emulation
#52 Add support for Rosetta 2 emulation on Macs with Apple Silicon (M1)
2 parents d343a6f + ce6256e commit 446dde5

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/main/java/io/zonky/test/db/postgres/embedded/DefaultPostgresBinaryResolver.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public InputStream getPgBinary(String system, String machineHardware) throws IOE
5050
if (distribution != null) {
5151
Resource resource = findPgBinary(normalize(format("postgres-%s-%s-%s.txz", system, architecture, distribution)));
5252
if (resource != null) {
53-
logger.info("Distribution specific postgres binaries found: {}", resource.getFilename());
53+
logger.info("Distribution specific postgres binaries found: '{}'", resource.getFilename());
5454
return resource.getInputStream();
5555
} else {
5656
logger.debug("Distribution specific postgres binaries not found");
@@ -59,13 +59,25 @@ public InputStream getPgBinary(String system, String machineHardware) throws IOE
5959

6060
Resource resource = findPgBinary(normalize(format("postgres-%s-%s.txz", system, architecture)));
6161
if (resource != null) {
62-
logger.info("System specific postgres binaries found: {}", resource.getFilename());
62+
logger.info("System specific postgres binaries found: '{}'", resource.getFilename());
6363
return resource.getInputStream();
6464
}
6565

66-
logger.error("No postgres binaries were found, you must add an appropriate maven dependency " +
67-
"that meets the following parameters - system: {}, architecture: {}", system, architecture);
68-
throw new IllegalStateException("Missing postgres binaries");
66+
if (StringUtils.equals(system, "Darwin") && StringUtils.equals(machineHardware, "aarch64")) {
67+
resource = findPgBinary(normalize(format("postgres-%s-%s.txz", system, "x86_64")));
68+
if (resource != null) {
69+
logger.warn("No native binaries supporting aarch64 architecture found. " +
70+
"Trying to use binaries for amd64 architecture instead: '{}'. " +
71+
"Make sure you have Rosetta 2 emulation enabled. " +
72+
"Note that performance may be degraded.", resource.getFilename());
73+
return resource.getInputStream();
74+
}
75+
}
76+
77+
logger.error("No postgres binaries found, you need to add an appropriate maven dependency " +
78+
"that meets the following parameters - system: '{}', architecture: '{}' " +
79+
"[https://github.com/zonkyio/embedded-postgres#additional-architectures]", system, architecture);
80+
throw new IllegalStateException("Missing embedded postgres binaries");
6981
}
7082

7183
private static Resource findPgBinary(String resourceLocation) throws IOException {
@@ -74,8 +86,8 @@ private static Resource findPgBinary(String resourceLocation) throws IOException
7486
List<URL> urls = Collections.list(classLoader.getResources(resourceLocation));
7587

7688
if (urls.size() > 1) {
77-
logger.error("Detected multiple binaries of the same architecture: {}", urls);
78-
throw new IllegalStateException("Duplicate postgres binaries");
89+
logger.error("Detected multiple binaries of the same architecture: '{}'", urls);
90+
throw new IllegalStateException("Duplicate embedded postgres binaries");
7991
}
8092
if (urls.size() == 1) {
8193
return new Resource(urls.get(0));

0 commit comments

Comments
 (0)