headers icon indicating copy to clipboard operation
headers copied to clipboard

Provide definitions for macros in rootless.h when !TARGET_OS_IPHONE

Open leptos-null opened this issue 1 year ago • 0 comments

What does this implement/fix? Explain your changes.

Theos only links libroot when targeting iphone: https://github.com/theos/theos/blob/351fbe83ee6058bdb64e90884c3bb047c31ab6c1/makefiles/instance/rules.mk#L139-L142

This is currently required because libroot is currently only compiled for iOS.

This PR seeks to match this linking behavior on the headers side: Only include libroot if the target is iOS.

When libroot is not available, this PR uses the definitions that were previously used in a2a4086

I opted for this approach so that projects that target both iOS and macOS, in particular, can use macros from rootless.h without needing to shim these macros or provide separate code for each target.

Checklist

  • [x] New code follows the code rules
  • [x] I've added modulemaps for any new libraries (e.g. see libactivator/module.modulemap): it should be possible to @import MyLibrary; in ObjC, or import MyLibrary in Swift.
  • [x] My contribution is code written by myself from reverse-engineered headers, licensed into the Public Domain as per LICENSE.md; or, code written by myself / taken from an existing project, released under an OSI-approved license, and I've added relevant licensing credit to LICENSE.md

Does this close any currently open issues?

No

Any relevant logs, error output, etc?

Some tests:

main.m:

#import <Foundation/Foundation.h>
#import <rootless.h>

int main(int argc, const char *argv[]) {
	printf("ROOT_PATH: %s\n", ROOT_PATH("/bin/"));
	printf("ROOT_PATH_VAR: %s\n", ROOT_PATH_VAR(argv[0]));

	printf("ROOT_PATH_NS: %s\n", ROOT_PATH_NS(@"/bin/").UTF8String);
	printf("ROOT_PATH_NS_VAR: %s\n", ROOT_PATH_NS_VAR(@(argv[0])).UTF8String);

	return 0;
}
  • Compiled for TARGET="macosx:clang:latest:11.0"
  • Compiled for TARGET="iphone:clang:latest:14.0"

Any other comments?

No

Where has this been tested?

Operating System: macOS

Platform: Darwin

Target Platform: iOS, macOS

Toolchain Version: Apple clang version 15.0.0 (clang-1500.3.9.4)

SDK Version: MacOSX14.5.sdk, iPhoneOS17.5.sdk

leptos-null avatar Aug 28 '24 17:08 leptos-null