This repository was archived by the owner on Sep 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
formula: stevengj/nlopt #516
Open
MeteorsLiu
wants to merge
2
commits into
xgo-dev:main
Choose a base branch
from
MeteorsLiu:issue/247-nlopt-luna
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,161 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| ) | ||
|
|
||
| const consumerSource = `#include <nlopt.h> | ||
|
|
||
| static double objective(unsigned n, const double *x, double *grad, void *data) | ||
| { | ||
| return x[0] * x[0]; | ||
| } | ||
|
|
||
| int main(void) | ||
| { | ||
| nlopt_opt opt = nlopt_create(NLOPT_LN_COBYLA, 1); | ||
| if (!opt) | ||
| return 1; | ||
| if (nlopt_set_min_objective(opt, objective, NULL) < 0) | ||
| return 1; | ||
| if (nlopt_set_xtol_rel(opt, 1e-6) < 0) | ||
| return 1; | ||
|
|
||
| double x = 1.0; | ||
| double minf; | ||
| if (nlopt_optimize(opt, &x, &minf) < 0) | ||
| return 1; | ||
| nlopt_destroy(opt); | ||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "stevengj/nlopt" | ||
|
|
||
| fromVer "v2.6.1" | ||
|
|
||
| defaults { | ||
| "shared": "OFF", | ||
| "fPIC": "ON", | ||
| "enable_cxx_routines": "ON", | ||
| } | ||
|
|
||
| filter => { | ||
| for name, values in target.options { | ||
| if name != "shared" && name != "fPIC" && name != "enable_cxx_routines" { | ||
| return false | ||
| } | ||
| for value in values { | ||
| if value != "ON" && value != "OFF" { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| onBuild ctx => { | ||
| installDir := ctx.outputDir | ||
| shared := target.options["shared"][0] == "ON" | ||
| fPIC := target.options["fPIC"][0] == "ON" | ||
| enableCxxRoutines := target.options["enable_cxx_routines"][0] == "ON" | ||
|
|
||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "CMAKE_INSTALL_LIBDIR", "lib" | ||
| c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5" | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| if !shared && !fPIC { | ||
| // The v2.6.1 CMakeLists probes HAS_FPIC before adding a global -fPIC | ||
| // flag. Pre-seed that probe so fPIC=OFF remains caller-controlled. | ||
| c.defineBool "HAS_FPIC", false | ||
| } | ||
| c.defineBool "NLOPT_CXX", enableCxxRoutines | ||
| c.defineBool "NLOPT_FORTRAN", false | ||
| c.defineBool "NLOPT_PYTHON", false | ||
| c.defineBool "NLOPT_OCTAVE", false | ||
| c.defineBool "NLOPT_MATLAB", false | ||
| c.defineBool "NLOPT_GUILE", false | ||
| c.defineBool "NLOPT_SWIG", false | ||
| c.defineBool "NLOPT_TESTS", false | ||
| c.defineBool "WITH_THREADLOCAL", true | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0o755)! | ||
| os.writeFile(filepath.join(licenseDir, "COPYING"), os.readFile(filepath.join(ctx.SourceDir, "COPYING"))!, 0o644)! | ||
|
|
||
| for subdir, name in { | ||
| "ags": "COPYRIGHT", | ||
| "bobyqa": "COPYRIGHT", | ||
| "cobyla": "COPYRIGHT", | ||
| "direct": "COPYING", | ||
| "esch": "COPYRIGHT", | ||
| "luksan": "COPYRIGHT", | ||
| "newuoa": "COPYRIGHT", | ||
| "slsqp": "COPYRIGHT", | ||
| "stogo": "COPYRIGHT", | ||
| } { | ||
| subdirDir := filepath.join(licenseDir, subdir) | ||
| os.mkdirAll(subdirDir, 0o755)! | ||
| sourcePath := filepath.join(ctx.SourceDir, "src", "algs", subdir, name) | ||
| os.writeFile(filepath.join(subdirDir, name), os.readFile(sourcePath)!, 0o644)! | ||
| } | ||
|
|
||
| osName := target.require["os"][0] | ||
| libs := ["-L$${libdir}", "-lnlopt"] | ||
| if osName == "linux" || osName == "freebsd" { | ||
| libs <- "-lm" | ||
| } | ||
| if !shared && enableCxxRoutines { | ||
| if osName == "darwin" { | ||
| libs <- "-lc++" | ||
| } else if osName != "windows" { | ||
| libs <- "-lstdc++" | ||
| } | ||
| } | ||
|
|
||
| cflags := ["-I$${includedir}"] | ||
| if osName == "windows" && shared { | ||
| cflags <- "-DNLOPT_DLL" | ||
| } | ||
|
|
||
| pcDir := filepath.join(installDir, "lib", "pkgconfig") | ||
| os.mkdirAll(pcDir, 0o755)! | ||
| pc := pkgconfig.new( | ||
| name = "NLopt", | ||
| description = "nonlinear optimization library", | ||
| version = "2.6.1", | ||
| libs = libs, | ||
| cflags = cflags, | ||
| )! | ||
| out := os.create(filepath.join(pcDir, "nlopt.pc"))! | ||
| pc.writeTo(out)! | ||
| out.close()! | ||
|
|
||
| pkgconfig.use installDir | ||
| ctx.setMetadata pkgconfig.lookup("nlopt")! | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0o755)! | ||
|
|
||
| consumer := filepath.join(testDir, "consumer.c") | ||
| os.writeFile(consumer, []byte(consumerSource), 0o644)! | ||
|
|
||
| pkgconfig.use installDir | ||
| flagsFile := filepath.join(testDir, "nlopt.flags") | ||
| os.writeFile(flagsFile, []byte(pkgconfig.lookup("nlopt")!), 0o644)! | ||
|
|
||
| binary := filepath.join(testDir, "consumer") | ||
| cc! consumer, "-o", binary, "@"+flagsFile | ||
|
|
||
| if target.options["shared"][0] == "ON" { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| } | ||
| exec! binary | ||
| } | ||
This file contains hidden or 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 @@ | ||
| {"path":"stevengj/nlopt","deps":{}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[P1] Do not expose ineffective fPIC=OFF for v2.8+
Because this formula serves every version from
v2.6.1onward, it also handlesv2.8.0+, whose upstreamCMakeLists.txtunconditionally sets thenlopttarget'sPOSITION_INDEPENDENT_CODEtoON. Consequently,CMAKE_POSITION_INDEPENDENT_CODE=OFFhere is ignored for those releases: an explicit--option fPIC=OFFstill compiles the static archive with-fPIC. That makes the retained option produce a result different from what callers requested. Please split the formula atv2.8.0(or otherwise remove/reject this option for that range) sofPIC=OFFis not advertised where upstream cannot honor it.