Merge pull request #612 from acco32/fsharp

Add nuget package for F#
This commit is contained in:
Mizux
2018-03-26 13:43:34 +02:00
committed by GitHub
6 changed files with 83 additions and 28 deletions

View File

@@ -16,28 +16,3 @@ fsharpc --target:exe --out:bin/<example_file>.exe --platform:anycpu --lib:bin ex
DYLD_FALLBACK_LIBRARY_PATH=lib mono bin/<example_file>.exe
```
## Compiling a standalone binary
This command must be run from the root folder of the repository:
```shell
fsharpc --target:library --out:bin/Google.OrTools.FSharp.dll --platform:anycpu --lib:bin --nocopyfsharpcore --keyfile:bin/keyfile.snk -r:Google.OrTools.dll ortools/fsharp/Google.OrTools.FSharp.fsx
```
For debug information add the `--debug` flag. The library must be coupled with the `Google.OrTools.dll`. Once installed it can be used as follows:
```fsharp
#r "Google.OrTools.dll"
#r "Google.OrTools.Fsharp.dll"
open System
open Google.OrTools.FSharp
let opts = SolverOpts.Default
.Name("Equality Constraints")
.Goal(Minimize)
...
```
One can also use the makefile found in the root folder to accomplish the same task.
```shell
make fsharp
```
To see the targets type `make fsharp-help`. Note that a keyfile must exists in the `bin` folder as it will be used to sign the assembly.

View File

@@ -124,9 +124,9 @@ NETSTANDARD_RUNTIME_IDENTIFIER=
# NuGet specification file name
ORTOOLS_NUSPEC_NAME := or-tools.nuspec
ORTOOLS_NUGET_DIR = temp\or-tools
ORTOOLS_NUGET_DIR = temp$Sor-tools
FZ_NUSPEC_NAME := fz.nuspec
FZ_NUGET_DIR = temp\flatzinc
FZ_NUGET_DIR = temp$Sflatzinc
# TODO: TBD: add FlatZinc variables...
# Building to DLLs named per-platform

View File

@@ -12,6 +12,10 @@ endif
BASE_ORTOOLS_DLL_NAME=Google.OrTools
FSHARP_ORTOOLS_DLL_NAME=$(BASE_ORTOOLS_DLL_NAME).FSharp
FSHARP_ORTOOLS_DLL_ASSEMBLYINFO_FILE=$(BASE_ORTOOLS_DLL_NAME).AssemblyInfo.fsx
FSHARP_ORTOOLS_NUSPEC_FILE=$(FSHARP_ORTOOLS_DLL_NAME).nuspec
CLEAN_FILES=$(FSHARP_ORTOOLS_DLL_NAME).*
# Check for required build tools
@@ -44,11 +48,18 @@ endif
.PHONY: fsharp # Build F# OR-Tools. Set environment variable FSHARP_DEBUG=1 for debug symbols.
fsharp: csharp
ifneq ($(FSHARP_EXECUTABLE),)
"$(FSHARP_EXECUTABLE)" $(FLAG_PREFIX)target:library $(FLAG_PREFIX)out:bin$S$(FSHARP_ORTOOLS_DLL_NAME).dll $(FLAG_PREFIX)platform:anycpu $(FS_NOCPYCORE) $(FLAG_PREFIX)lib:bin $(FLAG_PREFIX)reference:$(BASE_ORTOOLS_DLL_NAME).dll $(FSHARP_DEBUG) $(FS_SIGNING_FLAGS) ortools$Sfsharp$S$(FSHARP_ORTOOLS_DLL_NAME).fsx
$(SED) -i -e "s/MMMM/$(FSHARP_ORTOOLS_DLL_NAME)/" ortools$Sfsharp$S$(FSHARP_ORTOOLS_DLL_ASSEMBLYINFO_FILE)
$(SED) -i -e "s/VVVV/$(OR_TOOLS_VERSION)/" ortools$Sfsharp$S$(FSHARP_ORTOOLS_DLL_ASSEMBLYINFO_FILE)
"$(FSHARP_EXECUTABLE)" $(FLAG_PREFIX)target:library $(FLAG_PREFIX)out:bin$S$(FSHARP_ORTOOLS_DLL_NAME).dll $(FLAG_PREFIX)platform:anycpu $(FS_NOCPYCORE) $(FLAG_PREFIX)lib:bin $(FLAG_PREFIX)reference:$(BASE_ORTOOLS_DLL_NAME).dll $(FSHARP_DEBUG) $(FS_SIGNING_FLAGS) ortools$Sfsharp$S$(FSHARP_ORTOOLS_DLL_NAME).fsx ortools$Sfsharp$S$(FSHARP_ORTOOLS_DLL_ASSEMBLYINFO_FILE)
else
$(warning Cannot find '$(FSHARP_COMPILER)' command which is needed for build. Please make sure it is installed and in system path.)
endif
.PHONY: nuget-pkg_fsharp # Build Nuget Package for distribution.
nuget-pkg_fsharp: fsharp
$(SED) -i -e "s/VVVV/$(OR_TOOLS_VERSION)/" ortools$Sfsharp$S$(FSHARP_ORTOOLS_NUSPEC_FILE)
$(NUGET_EXECUTABLE) pack ortools$Sfsharp$S$(FSHARP_ORTOOLS_NUSPEC_FILE) -Basepath . -OutputDirectory $(ORTOOLS_NUGET_DIR)
.PHONY: test_fsharp # Test F# OR-Tools using various examples.
ifneq ($(FSHARP_EXECUTABLE),)
test_fsharp: test_fsharp_examples

View File

@@ -0,0 +1,15 @@
open System.Reflection
[<assembly: AssemblyTitle("MMMM")>]
[<assembly: AssemblyDescription(".NET F# Assembly for the Operations Research Tools project")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("Google Inc")>]
[<assembly: AssemblyProduct("Operations Research Tools")>]
[<assembly: AssemblyCopyright("Copyright © 2018")>]
[<assembly: AssemblyTrademark("")>]
[<assembly: AssemblyVersion("VVVV")>]
[<assembly: AssemblyFileVersion("VVVV")>]
()

View File

@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>Google.OrTools.FSharp</id>
<version>VVVV</version>
<authors>Google</authors>
<licenseUrl>https://github.com/google/or-tools/blob/master/LICENSE-2.0.txt</licenseUrl>
<projectUrl>https://developers.google.com/optimization</projectUrl>
<description>F# wrapper for the Operations Research Tools project</description>
<copyright>Copyright 2018 Google, Inc</copyright>
<tags>Operations Research Math Linear Constraint Programming F#</tags>
<dependencies>
<dependency id="Google.OrTools" version="VVVV" />
</dependencies>
</metadata>
<files>
<file src="bin/Google.OrTools.FSharp.dll" target="lib/netstandard2.0"/>
<file src="examples\fsharp\*.*" target="examples"/>
<file src="LICENSE-2.0.txt"/>
</files>
</package>

33
ortools/fsharp/README.md Normal file
View File

@@ -0,0 +1,33 @@
# Google OrTools - F#
## Compiling a standalone binary
This command must be run from the root folder of the repository:
```shell
fsharpc --target:library --out:bin/Google.OrTools.FSharp.dll --platform:anycpu --lib:bin --nocopyfsharpcore --keyfile:bin/keyfile.snk -r:Google.OrTools.dll ortools/fsharp/Google.OrTools.FSharp.fsx
```
For debug information add the `--debug` flag. The library must be coupled with the `Google.OrTools.dll`. Once installed it can be used as follows:
```fsharp
#r "Google.OrTools.dll"
#r "Google.OrTools.Fsharp.dll"
open System
open Google.OrTools.FSharp
let opts = SolverOpts.Default
.Name("Equality Constraints")
.Goal(Minimize)
...
```
One can also use the makefile found in the root folder to accomplish the same task.
```shell
make fsharp
```
To see the targets type `make help_fsharp`. Note that a keyfile must exist in the `bin` folder as it will be used to sign the assembly.
## Building Nuget package
Ensure nuget executable is installed and then from root folder run the following:
```shell
make nuget-pkg_fsharp
```
The output package will include the FSharp binary and examples. It is compiled against the `netstandard2.0` metaframework.