-
Notifications
You must be signed in to change notification settings - Fork 2
feat(libschrift): add LLAR formula #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| cmake_minimum_required(VERSION 3.8) | ||
| project(schrift LANGUAGES C) | ||
|
|
||
| include(GNUInstallDirs) | ||
|
|
||
| add_library(schrift ${LIBSCHRIFT_SRC_DIR}/schrift.c) | ||
| set_target_properties(schrift PROPERTIES | ||
| PUBLIC_HEADER ${LIBSCHRIFT_SRC_DIR}/schrift.h | ||
| WINDOWS_EXPORT_ALL_SYMBOLS ON | ||
| C_EXTENSIONS OFF | ||
| C_STANDARD 99 | ||
| ) | ||
|
|
||
| find_library(LIBM m) | ||
| target_link_libraries(schrift PRIVATE $<$<BOOL:${LIBM}>:${LIBM}>) | ||
|
|
||
| install( | ||
| TARGETS schrift | ||
| RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| "slices" | ||
| ) | ||
|
|
||
| const consumerSource = `#include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #include "schrift.h" | ||
|
|
||
| int main(void) { | ||
| printf("Schrift version: %s\n", sft_version()); | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } | ||
| ` | ||
|
|
||
| id "tomolt/libschrift" | ||
|
|
||
| fromVer "v0.10.1" | ||
|
|
||
| defaults { | ||
| "shared": "OFF", | ||
| "fPIC": "ON", | ||
| } | ||
|
|
||
| filter => { | ||
| for name, values in target.options { | ||
| if name != "shared" && name != "fPIC" { | ||
| return false | ||
| } | ||
| for value in values { | ||
| if value != "ON" && value != "OFF" { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| onBuild ctx => { | ||
| installDir := ctx.outputDir | ||
|
|
||
| cmakeLists := ctx.Proj.readFile("CMakeLists.txt")! | ||
| os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cmakeLists, 0644)! | ||
|
|
||
| shared := slices.contains(target.options["shared"], "ON") | ||
| fPIC := slices.contains(target.options["fPIC"], "ON") | ||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "LIBSCHRIFT_SRC_DIR", ctx.SourceDir | ||
| c.define "CMAKE_INSTALL_LIBDIR", "lib" | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0755)! | ||
| os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0644)! | ||
|
|
||
| osName := runtime.GOOS | ||
| osValues := target.require["os"] | ||
| if osValues.len > 0 { | ||
| osName = osValues[0] | ||
| } | ||
| metadata := "-I" + filepath.join(installDir, "include") + " -L" + filepath.join(installDir, "lib") + " -lschrift" | ||
| if osName == "linux" || osName == "freebsd" { | ||
| metadata += " -lm" | ||
| } | ||
| ctx.setMetadata metadata | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metadata is hand-built rather than derived from an installed pkg-config file. |
||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0755)! | ||
|
|
||
| consumer := filepath.join(testDir, "consumer.c") | ||
| os.writeFile(consumer, []byte(consumerSource), 0644)! | ||
|
|
||
| osName := runtime.GOOS | ||
| osValues := target.require["os"] | ||
| if osValues.len > 0 { | ||
| osName = osValues[0] | ||
| } | ||
| args := []string{ | ||
| "-I" + filepath.join(installDir, "include"), | ||
| consumer, | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lschrift", | ||
| } | ||
| if osName == "linux" || osName == "freebsd" { | ||
| args = append(args, "-lm") | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| binary := filepath.join(testDir, "consumer") | ||
| args = append(args, "-o", binary) | ||
| exec "cc", args... | ||
| lastErr! | ||
|
|
||
| if slices.contains(target.options["shared"], "ON") { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| exec binary | ||
| lastErr! | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "tomolt/libschrift", | ||
| "deps": {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
-lmdecision here is gated onosName == "linux" || "freebsd", whileCMakeLists.txt:14-15links libm wheneverfind_library(LIBM m)succeeds (any platform). These are two independent encodings of "does this platform need libm." For the default static build the consumer-side-lmis the load-bearing one (static archives don't record their deps), so on another Unix where libm exists but isn't in this list, the static library would build but consumers would fail to link. Deriving metadata from pkg-config (see the note atsetMetadata) would keep these in sync automatically; otherwise consider aligning the two conditions and adding a comment on the intended platform contract.