Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ default void splitMinecraftJar() {

Property<Boolean> getRuntimeOnlyLog4j();

/**
* When enabled, lwjgl-opengl or lwjgl-vulkan will be added as a runtime dependency preventing the mod from compiling against a specific graphics API.
*/
Property<Boolean> getRuntimeOnlyLwjglGraphics();

Property<Boolean> getSplitModDependencies();

<T extends RemapperParameters> void addRemapperExtension(Class<? extends RemapperExtension<T>> remapperExtensionClass, Class<T> parametersClass, Action<T> parameterAction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.fabricmc.loom.configuration.providers.minecraft.library.LibraryProcessorManager;
import net.fabricmc.loom.configuration.providers.minecraft.library.MinecraftLibraryHelper;
import net.fabricmc.loom.configuration.providers.minecraft.library.processors.RuntimeLog4jLibraryProcessor;
import net.fabricmc.loom.configuration.providers.minecraft.library.processors.RuntimeLwjglGraphicsLibraryProcessor;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.Platform;
import net.fabricmc.loom.util.gradle.GradleUtils;
Expand All @@ -70,6 +71,10 @@ private List<String> getEnabledProcessors() {
enabledProcessors.add(RuntimeLog4jLibraryProcessor.class.getSimpleName());
}

if (extension.getRuntimeOnlyLwjglGraphics().get()) {
enabledProcessors.add(RuntimeLwjglGraphicsLibraryProcessor.class.getSimpleName());
}

final Provider<String> libraryProcessorsProperty = project.getProviders().gradleProperty(Constants.Properties.LIBRARY_PROCESSORS);

if (libraryProcessorsProperty.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2026 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 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;

public class RuntimeLwjglGraphicsLibraryProcessor extends LibraryProcessor {
private static final String LWJGL_OPENGL = "org.lwjgl:lwjgl-opengl";
private static final String LWJGL_VULKAN = "org.lwjgl:lwjgl-vulkan";

public RuntimeLwjglGraphicsLibraryProcessor(Platform platform, LibraryContext context) {
super(platform, context);
}

@Override
public ApplicationResult getApplicationResult() {
return ApplicationResult.CAN_APPLY;
}

@Override
public Predicate<Library> apply(Consumer<Library> dependencyConsumer) {
return library -> {
if (library.is(LWJGL_OPENGL) || library.is(LWJGL_VULKAN)) {
dependencyConsumer.accept(library.withTarget(Library.Target.RUNTIME));
return false;
}

return true;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
private final Property<String> defaultMixinRemapType;
private final Property<Boolean> remapJsrAnnotationsToJetBrains;
private final Property<Boolean> runtimeOnlyLog4j;
private final Property<Boolean> runtimeOnlyLwjglGraphics;
private final Property<Boolean> splitModDependencies;
private final Property<MinecraftJarConfiguration<?, ?, ?>> minecraftJarConfiguration;
private final Property<Boolean> splitEnvironmentalSourceSet;
Expand Down Expand Up @@ -197,6 +198,9 @@ protected LoomGradleExtensionApiImpl(Project project, LoomFiles directories) {
this.runtimeOnlyLog4j = project.getObjects().property(Boolean.class).convention(false);
this.runtimeOnlyLog4j.finalizeValueOnRead();

this.runtimeOnlyLwjglGraphics = project.getObjects().property(Boolean.class).convention(false);
this.runtimeOnlyLwjglGraphics.finalizeValueOnRead();

this.splitModDependencies = project.getObjects().property(Boolean.class).convention(true);
this.splitModDependencies.finalizeValueOnRead();

Expand Down Expand Up @@ -440,6 +444,11 @@ public Property<Boolean> getRuntimeOnlyLog4j() {
return runtimeOnlyLog4j;
}

@Override
public Property<Boolean> getRuntimeOnlyLwjglGraphics() {
return runtimeOnlyLwjglGraphics;
}

@Override
public Property<Boolean> getSplitModDependencies() {
return splitModDependencies;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2026 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.RuntimeLwjglGraphicsLibraryProcessor
import net.fabricmc.loom.test.util.PlatformTestUtils

class RuntimeLwjglGraphicsLibraryProcessorTest extends LibraryProcessorTest {
def "Make lwjgl-opengl runtime"() {
when:
def (original, context) = getLibs("26.1-snapshot-10", PlatformTestUtils.MAC_OS_X64)
def processor = new RuntimeLwjglGraphicsLibraryProcessor(PlatformTestUtils.MAC_OS_X64, context)
def processed = mockLibraryProcessorManager().processLibraries([processor], original)

then:
processor.applicationResult == LibraryProcessor.ApplicationResult.CAN_APPLY

findLibrary("org.lwjgl:lwjgl-opengl", original).target() == Library.Target.COMPILE
findLibrary("org.lwjgl:lwjgl-opengl", processed).target() == Library.Target.RUNTIME
}
}
Loading