-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
279 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...om/configuration/providers/minecraft/library/processors/RiscVNativesLibraryProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* This file is part of fabric-loom, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) 2024 FabricMC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package net.fabricmc.loom.configuration.providers.minecraft.library.processors; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Predicate; | ||
|
||
import org.gradle.api.artifacts.dsl.RepositoryHandler; | ||
|
||
import net.fabricmc.loom.LoomRepositoryPlugin; | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.Library; | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.LibraryContext; | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.LibraryProcessor; | ||
import net.fabricmc.loom.util.Platform; | ||
|
||
/** | ||
* A processor to add support for RiscV. | ||
*/ | ||
public class RiscVNativesLibraryProcessor extends LibraryProcessor { | ||
private static final String LWJGL_GROUP = "org.lwjgl"; | ||
|
||
public RiscVNativesLibraryProcessor(Platform platform, LibraryContext context) { | ||
super(platform, context); | ||
} | ||
|
||
@Override | ||
public ApplicationResult getApplicationResult() { | ||
if (!context.usesLWJGL3()) { | ||
// Only supports LWJGL 3 | ||
return ApplicationResult.DONT_APPLY; | ||
} | ||
|
||
if (!platform.getArchitecture().isRiscV() || !platform.getArchitecture().is64Bit()) { | ||
// Not an RiscV platform, can never apply this. | ||
return ApplicationResult.DONT_APPLY; | ||
} | ||
|
||
if (!platform.getOperatingSystem().isLinux()) { | ||
// Only linux supports RiscV | ||
return ApplicationResult.DONT_APPLY; | ||
} | ||
|
||
if (!context.hasClasspathNatives()) { | ||
// Only upgrade versions using classpath natives | ||
return ApplicationResult.DONT_APPLY; | ||
} | ||
|
||
return ApplicationResult.MUST_APPLY; | ||
} | ||
|
||
@Override | ||
public Predicate<Library> apply(Consumer<Library> dependencyConsumer) { | ||
return library -> { | ||
// Add additional riscv64 natives for LWJGL, alongside the existing x64 linux natives. | ||
if (library.is(LWJGL_GROUP) && library.target() == Library.Target.NATIVES && (library.classifier() != null && library.classifier().equals("natives-linux"))) { | ||
// Add the riscv64 natives. | ||
dependencyConsumer.accept(library.withClassifier(library.classifier() + "-riscv64")); | ||
} | ||
|
||
return true; | ||
}; | ||
} | ||
|
||
@Override | ||
public void applyRepositories(RepositoryHandler repositories) { | ||
LoomRepositoryPlugin.forceLWJGLFromMavenCentral(repositories); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...vy/net/fabricmc/loom/test/unit/library/processors/RiscVNativesLibraryProcessorTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* This file is part of fabric-loom, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) 2024 FabricMC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package net.fabricmc.loom.test.unit.library.processors | ||
|
||
import net.fabricmc.loom.configuration.providers.minecraft.library.Library | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.LibraryProcessor | ||
import net.fabricmc.loom.configuration.providers.minecraft.library.processors.RiscVNativesLibraryProcessor | ||
import net.fabricmc.loom.test.util.PlatformTestUtils | ||
|
||
class RiscVNativesLibraryProcessorTest extends LibraryProcessorTest { | ||
def "Apply when adding linux riscv support"() { | ||
when: | ||
def (_, context) = getLibs(id, PlatformTestUtils.LINUX_RISCV) | ||
def processor = new RiscVNativesLibraryProcessor(PlatformTestUtils.LINUX_RISCV, context) | ||
then: | ||
processor.applicationResult == result | ||
|
||
where: | ||
id || result | ||
"1.21" || LibraryProcessor.ApplicationResult.MUST_APPLY | ||
"1.20.1" || LibraryProcessor.ApplicationResult.MUST_APPLY | ||
"1.14.4" || LibraryProcessor.ApplicationResult.DONT_APPLY // Not using classpath natives | ||
"1.12.2" || LibraryProcessor.ApplicationResult.DONT_APPLY // Not LWJGL 3 | ||
} | ||
|
||
def "Never apply on none riscv platforms"() { | ||
when: | ||
def (_, context) = getLibs(id, platform) | ||
def processor = new RiscVNativesLibraryProcessor(platform, context) | ||
then: | ||
processor.applicationResult == LibraryProcessor.ApplicationResult.DONT_APPLY | ||
|
||
where: | ||
id | platform | ||
"1.21" | PlatformTestUtils.LINUX_ARM64 | ||
"1.21" | PlatformTestUtils.LINUX_X64 | ||
"1.19.4" | PlatformTestUtils.MAC_OS_X64 | ||
"1.18.2" | PlatformTestUtils.WINDOWS_X64 | ||
"1.17.1" | PlatformTestUtils.MAC_OS_X64 | ||
"1.16.5" | PlatformTestUtils.MAC_OS_X64 | ||
"1.15.2" | PlatformTestUtils.LINUX_X64 | ||
"1.14.4" | PlatformTestUtils.MAC_OS_X64 | ||
"1.12.2" | PlatformTestUtils.WINDOWS_X64 | ||
} | ||
|
||
def "Add linux riscv natives"() { | ||
when: | ||
def (original, context) = getLibs("1.21", PlatformTestUtils.LINUX_RISCV) | ||
def processor = new RiscVNativesLibraryProcessor(PlatformTestUtils.LINUX_RISCV, context) | ||
def processed = mockLibraryProcessorManager().processLibraries([processor], original) | ||
|
||
then: | ||
// Test that the riscv64 natives are added alongside the existing ones | ||
def originalNatives = original.findAll { it.is("org.lwjgl") && it.target() == Library.Target.NATIVES } | ||
originalNatives.count { it.classifier() == "natives-linux-riscv64" } == 0 | ||
originalNatives.count { it.classifier() == "natives-linux" } > 0 | ||
|
||
def processedNatives = processed.findAll { it.is("org.lwjgl") && it.target() == Library.Target.NATIVES } | ||
processedNatives.count { it.classifier() == "natives-linux-riscv64" } > 0 | ||
processedNatives.count { it.classifier() == "natives-linux" } > 0 | ||
} | ||
} |
Oops, something went wrong.