Skip to content

#52 Add support for Rosetta 2 emulation on Macs with Apple Silicon (M1) #60

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

Merged
merged 1 commit into from
Jun 13, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public InputStream getPgBinary(String system, String machineHardware) throws IOE
if (distribution != null) {
Resource resource = findPgBinary(normalize(format("postgres-%s-%s-%s.txz", system, architecture, distribution)));
if (resource != null) {
logger.info("Distribution specific postgres binaries found: {}", resource.getFilename());
logger.info("Distribution specific postgres binaries found: '{}'", resource.getFilename());
return resource.getInputStream();
} else {
logger.debug("Distribution specific postgres binaries not found");
Expand All @@ -59,13 +59,25 @@ public InputStream getPgBinary(String system, String machineHardware) throws IOE

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

logger.error("No postgres binaries were found, you must add an appropriate maven dependency " +
"that meets the following parameters - system: {}, architecture: {}", system, architecture);
throw new IllegalStateException("Missing postgres binaries");
if (StringUtils.equals(system, "Darwin") && StringUtils.equals(machineHardware, "aarch64")) {
resource = findPgBinary(normalize(format("postgres-%s-%s.txz", system, "x86_64")));
if (resource != null) {
logger.warn("No native binaries supporting aarch64 architecture found. " +
"Trying to use binaries for amd64 architecture instead: '{}'. " +
"Make sure you have Rosetta 2 emulation enabled. " +
"Note that performance may be degraded.", resource.getFilename());
return resource.getInputStream();
}
}

logger.error("No postgres binaries found, you need to add an appropriate maven dependency " +
"that meets the following parameters - system: '{}', architecture: '{}' " +
"[https://github.com/zonkyio/embedded-postgres#additional-architectures]", system, architecture);
throw new IllegalStateException("Missing embedded postgres binaries");
}

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

if (urls.size() > 1) {
logger.error("Detected multiple binaries of the same architecture: {}", urls);
throw new IllegalStateException("Duplicate postgres binaries");
logger.error("Detected multiple binaries of the same architecture: '{}'", urls);
throw new IllegalStateException("Duplicate embedded postgres binaries");
}
if (urls.size() == 1) {
return new Resource(urls.get(0));
Expand Down