-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
1 parent
079cb52
commit bc9a4c6
Showing
7 changed files
with
113 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
|
||
*.o |
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,12 @@ | ||
ARCH = $(shell uname -m) | ||
|
||
liblzld_${ARCH}.a: lzld.m | ||
cc -c lzld.m -o lzld.o | ||
ar rcs liblzld_${ARCH}.a lzld.o | ||
|
||
clean: | ||
rm -f liblzld_${ARCH}.a lzld.o | ||
|
||
all: liblzld_${ARCH}.a | ||
|
||
.PHONY: clean all |
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,39 @@ | ||
A `ld -lazy_framework` for macOS. Designed to build Deno. | ||
|
||
## Usage | ||
|
||
```toml | ||
[target.aarch64-apple-darwin] | ||
rustflags = [ | ||
"-C", | ||
"linker=/path/to/lzld/lzld", | ||
"-C", | ||
"link-args=-L/path/to/lzld -llzld" | ||
] | ||
``` | ||
|
||
### Usage without `lzld` wrapper | ||
|
||
1. `rustc -Z link-native-libraries=no -L/path/to/lzld -llzld`: | ||
Requires nightly but doesn't need a wrapper linker. | ||
|
||
2. Manaully source modification: Remove `#[link]` attributes | ||
from all dependencies and link to `liblzld.a`. | ||
|
||
## Design | ||
|
||
It's pretty simple. Drop in `lzld` as the linker. | ||
It strips out `-framework` arguments and links a | ||
static library (`liblzld.a`) that will lazy load | ||
the framework via `dlopen` when needed. | ||
|
||
Rest of the arguments are passed as-is to `lld`. | ||
|
||
<!-- | ||
Supported frameworks: | ||
- QuartzCore | ||
- CoreFoundation | ||
- TODO | ||
--> | ||
|
||
|
Binary file not shown.
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,26 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Find the path to the `lld` binary. | ||
lld=$(which lld) | ||
if [ ! -x "$lld" ]; then | ||
echo "Error: unable to find 'lld' binary" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Filter out `-framework` arguments. | ||
args=() | ||
while [ $# -gt 0 ]; do | ||
case "$1" in | ||
-framework) | ||
shift 2 | ||
;; | ||
*) | ||
args+=("$1") | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
# Run `lld` with the filtered arguments. | ||
exec "$lld" "${args[@]}" |
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,25 @@ | ||
#import <dlfcn.h> | ||
|
||
// -- QuartzCore.framework | ||
|
||
extern void *kCAGravityTopLeft = 0; | ||
|
||
// -- Metal.framework | ||
|
||
void *(*MTLCopyAllDevices_)(void) = 0; | ||
|
||
void loadMetalFramework() { | ||
void *handle = dlopen("/System/Library/Frameworks/Metal.framework/Metal", RTLD_LAZY); | ||
if (handle) { | ||
MTLCopyAllDevices_ = dlsym(handle, "MTLCopyAllDevices"); | ||
} | ||
} | ||
|
||
extern void *MTLCopyAllDevices(void) { | ||
if (MTLCopyAllDevices_ == 0) { | ||
loadMetalFramework(); | ||
} | ||
|
||
return MTLCopyAllDevices_(); | ||
} | ||
|