Initial commit. Compilation works.

This commit is contained in:
vijay gopal chilkuri 2020-11-15 07:43:48 +01:00
commit 846d926516
6 changed files with 179 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*LTemplate*
*LibraryResources/MacOSX-x86-64-libc++/*
*Testing/*nb
*DS_Store*

36
BuildSettings.m Normal file
View File

@ -0,0 +1,36 @@
(* Specify build settings such as compiler and linker flags, libraries to be linked, etc. here *)
Switch[$OperatingSystem,
"MacOSX", (* Compilation settings for OS X *)
$buildSettings = {
"CompileOptions" -> {(* "-std=c++14", "-mmacosx-version-min=10.9" *)},
(* Statically link the tree library *)
"ExtraObjectFiles" -> {"/Users/chilkuri/Documents/postdoc/sandbox/python/guga_ice/lib/libgugaice.dylib"},
(* Tree path *)
"IncludeDirectories" -> {"/Users/chilkuri/Documents/postdoc/sandbox/python/guga_ice/lib/Tree","/Users/chilkuri/Documents/postdoc/sandbox/python/guga_ice/lib/Tools"},
"LibraryDirectories" -> {"/Users/chilkuri/Documents/postdoc/sandbox/python/guga_ice/lib/"}
},
"Unix", (* Compilation settings for Linux *)
$buildSettings = {
"CompileOptions" -> {(* "-std=c++14" *)}
(*
, "IncludeDirectories" -> {}
, "LibraryDirectories" -> {}
*)
},
"Windows", (* Compilation settings for Windows *)
$buildSettings = {
"CompileOptions" -> {"/EHsc", "/wd4244", "/DNOMINMAX"}
(*
, "IncludeDirectories" -> {}
, "LibraryDirectories" -> {}
*)
}
]

5
Kernel/init.m Normal file
View File

@ -0,0 +1,5 @@
Get["TestPackage`TestPackage`"]
Column@{
"TestPackage [" <> TestPackage`TestPackage`PackagePrivate`$packageVersion <> "]"
}

View File

@ -0,0 +1,7 @@
#include <LTemplate.h>
class TestPackage {
public:
double version() const {return 0.2;}
};

111
TestPackage.m Normal file
View File

@ -0,0 +1,111 @@
Package["TestPackage`"]
PackageImport["TestPackage`LTemplate`"]
PackageExport["TestPackage"]
TestPackage::usage = "TestPackage is used to test MMAs new package system."
TestPackage[] :=Module[{},Return["Hello world: " <> TestPackage`TestPackageVersion[] ]];
(***** Package variables *****)
PackageScope["$packageDirectory"]
$packageDirectory::usage = "$packageDirectory is the directory where TestPackage is installed.";
$packageVersion = "0.0.1";
$packageDirectory = DirectoryName[$InputFileName];
$systemID = $SystemID;
(* On OS X libraries use libc++ ABI since M10.4 and libstdc++ ABI up to M10.3.
We need separate binaries to support M10.3 and earlier.
http://community.wolfram.com/groups/-/m/t/816033 *)
If[$OperatingSystem === "MacOSX", $systemID = $systemID <> If[$VersionNumber <= 10.3, "-libstdc++", "-libc++"]];
$libraryDirectory = FileNameJoin[{$packageDirectory, "LibraryResources", $systemID}];
$sourceDirectory = FileNameJoin[{$packageDirectory, "LibraryResources", "Source"}];
$buildSettingsFile = FileNameJoin[{$packageDirectory, "BuildSettings.m"}];
(* Add $libraryDirectory to $LibraryPath in case package is not installed in $UserBaseDirectory/Applications. *)
If[Not@MemberQ[$LibraryPath, $libraryDirectory],
PrependTo[$LibraryPath, $libraryDirectory]
]
(***** The library template *****)
template =LTemplate["TestPackage",
{
LClass["TestPackage",
{
LFun["version", {}, Real]
}
]
}
];
(***** Load build settings, if present *****)
(* $buildSettings is normally defined in the build settings files.
When no build settings file is loaded, it must be set to None. *)
$buildSettings = None;
If[FileExistsQ[$buildSettingsFile], Get[$buildSettingsFile] ]
TestPackage`Developer`Recompile::build = "No build settings found. Please check BuildSettings.m."
TestPackage`Developer`Recompile[] :=
Module[{},
(* abort compilation if no build settings are present *)
If[$buildSettings === None,
Message[TestPackage`Developer`Recompile::build];
Return[$Failed]
];
(* create directory for binary if it doesn't exist yet *)
If[Not@DirectoryQ[$libraryDirectory],
CreateDirectory[$libraryDirectory]
];
(* compile code *)
SetDirectory[$sourceDirectory];
CompileTemplate[template, { },
"ShellCommandFunction" -> Print, "ShellOutputFunction" -> Print,
"TargetDirectory" -> $libraryDirectory,
Sequence @@ $buildSettings
];
Print["Compiling2"];
ResetDirectory[];
(* load library *)
loadTestPackage[] (* defined below *)
]
loadTestPackage[] :=
Module[{deps},
(* mechanism for loading shared library dependencies, if necessary *)
deps = FileNameJoin[{$libraryDirectory, "dependencies.m"}];
Check[
If[FileExistsQ[deps], Get[deps]],
Return[$Failed]
];
(* load the library *)
If[LoadTemplate[template] === $Failed,
Return[$Failed]
];
(* TODO add any other post-loading initialization if necessary *)
]
(* Load library, compile if necessary. *)
If[LoadTemplate[template] === $Failed,
Print[Style["Loading failed, trying to recompile ...", Red]];
If[TestPackage`Developer`Recompile[] === $Failed
,
Print[Style["Cannot load or compile library. \[SadSmiley] Aborting.", Red]];
Abort[] (* verified that it is safe to abort while loading a new-style package *)
,
Print[Style["Successfully compiled and loaded the library. \[HappySmiley]", Red]];
]
]

16
Utilities.m Normal file
View File

@ -0,0 +1,16 @@
Package["TestPackage`"]
PackageImport["TestPackage`LTemplate`"]
PackageExport["TestPackageVersion"]
TestPackageVersion::usage = "TestPackageVersion returns the current version of the package."
(***** Definitions of package functions *****)
obj = ""
PackageExport[TestPackageVersion]
SyntaxInformation[TestPackageVersion] = {"ArgumentsPattern" -> {}};
TestPackageVersion[] := Block[{obj = Make["TestPackage"]}, obj@"version"[]] (* TODO example function, remove if not used *)