Skip to content

Commit

Permalink
feat: add support for FreeBSD x64
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Nov 22, 2023
1 parent af2766e commit 2dcd0e2
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 23 deletions.
8 changes: 8 additions & 0 deletions client/routes/customize/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export function getDefaultPlatform(): Native {
return Native.MacOSARM64;
}
return Native.MacOS;
} else if (platform.toLowerCase().includes('freebsd')) {
return Native.FreeBSD;
} else if (platform.toLowerCase().includes('linux')) {
if (arch !== null) {
if (arch.indexOf('arm') > -1) {
Expand Down Expand Up @@ -112,6 +114,11 @@ function getInitialConfig(): BuildStore {
},
natives: {
byId: {
[Native.FreeBSD]: {
id: Native.FreeBSD,
title: 'FreeBSD x64',
since: Version.LWJGL334,
},
[Native.Linux]: {
id: Native.Linux,
title: 'Linux x64',
Expand Down Expand Up @@ -285,6 +292,7 @@ function getInitialConfig(): BuildStore {
includeJSON: true,
language: Language.Groovy,
platform: {
[Native.FreeBSD]: false,
[Native.Linux]: false,
[Native.LinuxARM64]: false,
[Native.LinuxARM32]: false,
Expand Down
2 changes: 2 additions & 0 deletions client/routes/customize/lib/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ export function getFiles(

function pathToNative(folder: string): Native | null {
switch (folder) {
case 'freebsd':
return Native.FreeBSD;
case 'linux':
return Native.Linux;
case 'linux-arm64':
Expand Down
3 changes: 3 additions & 0 deletions client/routes/customize/lib/getPlatformIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Native } from '../types';
import { Icon } from '~/components/ui/Icon';
import '~/theme/icons/fa/brands/apple';
import '~/theme/icons/fa/brands/freebsd';
import '~/theme/icons/fa/brands/linux';
import '~/theme/icons/fa/brands/windows';

export const getPlatformIcon = (platform: Native) => {
switch (platform) {
case Native.FreeBSD:
return <Icon aria-label="FreeBSD" name="fa/brands/freebsd" key={`fa-${platform}`} />;
case Native.Linux:
case Native.LinuxARM64:
case Native.LinuxARM32:
Expand Down
27 changes: 19 additions & 8 deletions client/routes/customize/lib/gradle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function generateGradle({
}
if (platformSingle === null) {
const linuxArches =
+platform.linux +
+platform['linux'] +
+platform['linux-arm64'] +
+platform['linux-arm32'] +
+platform['linux-ppc64le'] +
Expand All @@ -55,6 +55,12 @@ export function generateGradle({
const windowsArches = +platform.windows + +platform['windows-x86'] + +platform['windows-arm64'];
if (language === Language.Groovy) {
script += `switch (OperatingSystem.current()) {`;
if (platform.freebsd) {
script += `
\tcase OperatingSystem.FREE_BSD:
\t\tproject.ext.lwjglNatives = "natives-freebsd"
\t\tbreak`
}
if (linuxArches != 0) {
script +=
linuxArches == 1
Expand Down Expand Up @@ -108,12 +114,16 @@ export function generateGradle({
\tSystem.getProperty("os.arch")!!
).let { (name, arch) ->
\twhen {`;
if (platform.freebsd) {
script += `\n\t\t"FreeBSD".equals(name) ->
\t\t\t"natives-freebsd"`
}
if (linuxArches != 0) {
script +=
linuxArches == 1
? `\n\t\tarrayOf("Linux", "FreeBSD", "SunOS", "Unit").any { name.startsWith(it) } ->
? `\n\t\tarrayOf("Linux", "SunOS", "Unit").any { name.startsWith(it) } ->
\t\t\t"natives-linux${getLinuxSuffix(platform)}"`
: `\n\t\tarrayOf("Linux", "FreeBSD", "SunOS", "Unit").any { name.startsWith(it) } ->
: `\n\t\tarrayOf("Linux", "SunOS", "Unit").any { name.startsWith(it) } ->
\t\t\tif (arrayOf("arm", "aarch64").any { arch.startsWith(it) })
\t\t\t\t"natives-linux\${if (arch.contains("64") || arch.startsWith("armv8")) "-arm64" else "-arm32"}"
\t\t\telse if (arch.startsWith("ppc"))
Expand All @@ -126,24 +136,25 @@ export function generateGradle({
if (macosArches != 0) {
script +=
macosArches == 1
? `\n\t\tarrayOf("Mac OS X", "Darwin").any { name.startsWith(it) } ->
? `\n\t\tarrayOf("Mac OS X", "Darwin").any { name.startsWith(it) } ->
\t\t\t"natives-macos${platform.macos ? '' : '-arm64'}"`
: `\n\t\tarrayOf("Mac OS X", "Darwin").any { name.startsWith(it) } ->
: `\n\t\tarrayOf("Mac OS X", "Darwin").any { name.startsWith(it) } ->
\t\t\t"natives-macos\${if (arch.startsWith("aarch64")) "-arm64" else ""}"`;
}
if (windowsArches != 0) {
script +=
windowsArches == 1
? `\n\t\tarrayOf("Windows").any { name.startsWith(it) } ->
? `\n\t\tarrayOf("Windows").any { name.startsWith(it) } ->
\t\t\t"natives-windows${platform.windows ? '' : platform['windows-arm64'] ? '-arm64' : '-x86'}"`
: `\n\t\tarrayOf("Windows").any { name.startsWith(it) } ->
: `\n\t\tarrayOf("Windows").any { name.startsWith(it) } ->
\t\t\tif (arch.contains("64"))
\t\t\t\t"natives-windows\${if (arch.startsWith("aarch64")) "-arm64" else ""}"
\t\t\telse
\t\t\t\t"natives-windows-x86"`;
}
script += `
\t\telse -> throw Error("Unrecognized or unsupported platform. Please set \\"lwjglNatives\\" manually")
\t\telse ->
\t\t\tthrow Error("Unrecognized or unsupported platform. Please set \\"lwjglNatives\\" manually")
\t}
}
\n\n`;
Expand Down
6 changes: 5 additions & 1 deletion client/routes/customize/lib/ivy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ export function generateIvy({

if (platformSingle === null) {
script += `<!-- Add to build.xml -->`;
if (platform.freebsd) {
script += `
<condition property="lwjgl.natives" value="natives-freebsd">${nl2}<os name="FreeBSD"/>${nl1}</condition>`;
}
const linuxArches =
+platform.linux +
+platform['linux'] +
+platform['linux-arm64'] +
+platform['linux-arm32'] +
+platform['linux-ppc64le'] +
Expand Down
31 changes: 17 additions & 14 deletions client/routes/customize/lib/maven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function generateMaven({
}

if (platformSingle === null) {
const generateProfile = (profile: Native, family: string, arch: string, natives: String) => {
const generateProfile = (profile: Native, family: string, name: string | null, arch: string, natives: String) => {
let dependencies = selected
.filter((binding) => {
const artifact = artifacts[binding];
Expand All @@ -63,42 +63,45 @@ export function generateMaven({
}${nl5}<classifier>${natives}</classifier>${nl4}</dependency>`;
});

return `\n\t<profile>${nl3}<id>lwjgl-natives-${profile}-${arch}</id>${nl3}<activation>${nl4}<os>${nl5}<family>${family}</family>${nl5}<arch>${arch}</arch>${nl4}</os>${nl3}</activation>${nl3}<properties>${nl4}<lwjgl.natives>${natives}</lwjgl.natives>${nl3}</properties>${
return `\n\t<profile>${nl3}<id>lwjgl-natives-${profile}-${arch}</id>${nl3}<activation>${nl4}<os>${nl5}<family>${family}</family>${name === null ? '' : '${nl5}<name>${name}</name>'}${nl5}<arch>${arch}</arch>${nl4}</os>${nl3}</activation>${nl3}<properties>${nl4}<lwjgl.natives>${natives}</lwjgl.natives>${nl3}</properties>${
dependencies.length === 0 ? '' : `${nl3}<dependencies>${dependencies.join(nl4)}${nl3}</dependencies>`
}${nl2}</profile>`;
};

script += '<profiles>';
if (platform.freebsd) {
script += generateProfile(Native.FreeBSD, 'unix', 'freebsd', 'amd64', 'natives-freebsd');
}
if (platform.linux) {
script += generateProfile(Native.Linux, 'unix', 'amd64', 'natives-linux');
script += generateProfile(Native.Linux, 'unix', 'linux', 'amd64', 'natives-linux');
}
if (platform['linux-arm64']) {
script += generateProfile(Native.Linux, 'unix', 'aarch64', 'natives-linux-arm64');
script += generateProfile(Native.Linux, 'unix', 'linux', 'aarch64', 'natives-linux-arm64');
}
if (platform['linux-arm32']) {
script += generateProfile(Native.Linux, 'unix', 'arm', 'natives-linux-arm32');
script += generateProfile(Native.Linux, 'unix', 'arm32', 'natives-linux-arm32');
script += generateProfile(Native.Linux, 'unix', 'linux', 'arm', 'natives-linux-arm32');
script += generateProfile(Native.Linux, 'unix', 'linux', 'arm32', 'natives-linux-arm32');
}
if (platform['linux-ppc64le']) {
script += generateProfile(Native.Linux, 'unix', 'ppc64le', 'natives-linux-ppc64le');
script += generateProfile(Native.Linux, 'unix', 'linux', 'ppc64le', 'natives-linux-ppc64le');
}
if (platform['linux-riscv64']) {
script += generateProfile(Native.Linux, 'unix', 'riscv64', 'natives-linux-riscv64');
script += generateProfile(Native.Linux, 'unix', 'linux', 'riscv64', 'natives-linux-riscv64');
}
if (platform.macos) {
script += generateProfile(Native.MacOS, 'mac', 'x86_64', 'natives-macos');
script += generateProfile(Native.MacOS, 'mac', null, 'x86_64', 'natives-macos');
}
if (platform['macos-arm64']) {
script += generateProfile(Native.MacOS, 'mac', 'aarch64', 'natives-macos-arm64');
script += generateProfile(Native.MacOS, 'mac', null, 'aarch64', 'natives-macos-arm64');
}
if (platform.windows) {
script += generateProfile(Native.Windows, 'windows', 'amd64', 'natives-windows');
script += generateProfile(Native.Windows, 'windows', null, 'amd64', 'natives-windows');
}
if (platform['windows-x86']) {
script += generateProfile(Native.Windows, 'windows', 'x86', 'natives-windows-x86');
script += generateProfile(Native.Windows, 'windows', null, 'x86', 'natives-windows-x86');
}
if (platform['windows-arm64']) {
script += generateProfile(Native.Windows, 'windows', 'aarch64', 'natives-windows-arm64');
script += generateProfile(Native.Windows, 'windows', null, 'aarch64', 'natives-windows-arm64');
}
script += '\n</profiles>\n\n';
}
Expand Down Expand Up @@ -146,7 +149,7 @@ export function generateMaven({
return `\n\t<dependency>${nl3}<groupId>${groupId}</groupId>${nl3}<artifactId>${artifactId}</artifactId>${
hasBoM ? '' : `${nl3}<version>${v}</version>`
}${nl3}<classifier>${classifier}</classifier>${nl2}</dependency>`;
},
}
);

selectedAddons.forEach((id: Addon) => {
Expand Down
2 changes: 2 additions & 0 deletions client/routes/customize/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export enum BuildType {
}

export enum Native {
FreeBSD = 'freebsd',
Linux = 'linux',
LinuxARM64 = 'linux-arm64',
LinuxARM32 = 'linux-arm32',
Expand All @@ -106,6 +107,7 @@ export const NATIVE_LTE_333 = [
Native.WindowsARM64,
];
export const NATIVE_ALL = [
Native.FreeBSD,
Native.Linux,
Native.LinuxARM64,
Native.LinuxARM32,
Expand Down
1 change: 1 addition & 0 deletions client/routes/customize/versions/nightly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default (prev: BuildBindings): BuildBindings => ({
[Binding.OPENXR]: {
...(prev.byId[Binding.OPENXR] as BindingDefinition),
natives: [
Native.FreeBSD,
Native.Linux,
Native.LinuxARM64,
Native.LinuxARM32,
Expand Down
4 changes: 4 additions & 0 deletions client/theme/icons/fa/brands/freebsd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { register } from '~/theme/icons/sheet';
register(
`<symbol id="fa/brands/freebsd" viewBox="0 0 448 512"><path d="M303.7 96.2c11.1-11.1 115.5-77 139.2-53.2 23.7 23.7-42.1 128.1-53.2 139.2-11.1 11.1-39.4.9-63.1-22.9-23.8-23.7-34.1-52-22.9-63.1zM109.9 68.1C73.6 47.5 22 24.6 5.6 41.1c-16.6 16.6 7.1 69.4 27.9 105.7 18.5-32.2 44.8-59.3 76.4-78.7zM406.7 174c3.3 11.3 2.7 20.7-2.7 26.1-20.3 20.3-87.5-27-109.3-70.1-18-32.3-11.1-53.4 14.9-48.7 5.7-3.6 12.3-7.6 19.6-11.6-29.8-15.5-63.6-24.3-99.5-24.3-119.1 0-215.6 96.5-215.6 215.6 0 119 96.5 215.6 215.6 215.6S445.3 380.1 445.3 261c0-38.4-10.1-74.5-27.7-105.8-3.9 7-7.6 13.3-10.9 18.8z"/></symbol>`,
);

0 comments on commit 2dcd0e2

Please sign in to comment.