Skip to content

Commit 9adf131

Browse files
committed
Initial commit
0 parents  commit 9adf131

File tree

5 files changed

+250
-0
lines changed

5 files changed

+250
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Compile WL function(s)
2+
on: [push]
3+
jobs:
4+
FunctionCompile-Windows-x86-64:
5+
runs-on: windows-latest
6+
env:
7+
WOLFRAM_SYSTEM_ID: Windows-x86-64
8+
WOLFRAMENGINE_INSTALL_MSI_DOWNLOAD_URL: https://files.wolframcdn.com/packages/winget/12.2.0.0/WolframEngine_12.2.0_WIN.msi
9+
WOLFRAMENGINE_CACHE_KEY: WolframEngine-A
10+
WOLFRAMENGINE_INSTALLATION_SUBDIRECTORY: WolframEngine
11+
steps:
12+
- name: Check out repository
13+
uses: actions/checkout@v2
14+
15+
- name: Cache/restore Wolfram Engine install
16+
id: cache-restore
17+
uses: actions/cache@v2
18+
env:
19+
WOLFRAMENGINE_INSTALLATION_DIRECTORY: '${{ runner.temp }}\${{ env.WOLFRAMENGINE_INSTALLATION_SUBDIRECTORY }}'
20+
with:
21+
path: ${{ env.WOLFRAMENGINE_INSTALLATION_DIRECTORY }}
22+
key: wolframengine-${{ env.WOLFRAM_SYSTEM_ID }}-${{ env.WOLFRAMENGINE_CACHE_KEY }}
23+
24+
- name: Download and install Wolfram Engine
25+
if: steps.cache-restore.outputs.cache-hit != 'true'
26+
env:
27+
WOLFRAMENGINE_INSTALLATION_DIRECTORY: '${{ runner.temp }}\${{ env.WOLFRAMENGINE_INSTALLATION_SUBDIRECTORY }}'
28+
WOLFRAMENGINE_INSTALL_MSI_PATH: '${{ runner.temp }}\WolframEngine-Install.msi'
29+
WOLFRAMENGINE_INSTALL_LOG_PATH: '${{ runner.temp }}\WolframEngine-Install.log'
30+
run: |
31+
echo 'Downloading Wolfram Engine installer...'
32+
$msiFile = '${{ env.WOLFRAMENGINE_INSTALL_MSI_PATH }}'
33+
$logFile = '${{ env.WOLFRAMENGINE_INSTALL_LOG_PATH }}'
34+
35+
Import-Module BitsTransfer
36+
Start-BitsTransfer '${{ env.WOLFRAMENGINE_INSTALL_MSI_DOWNLOAD_URL }}' $msiFile
37+
echo 'Downloaded Wolfram Engine installer.'
38+
39+
$DataStamp = get-date -Format yyyyMMddTHHmmss
40+
$MSIArguments = @(
41+
"/i"
42+
('"{0}"' -f $msiFile)
43+
'INSTALLLOCATION="${{ env.WOLFRAMENGINE_INSTALLATION_DIRECTORY }}"'
44+
"/qn"
45+
"/norestart"
46+
"/L*v"
47+
$logFile
48+
)
49+
echo 'Installing Wolfram Engine...'
50+
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow
51+
echo 'Installed Wolfram Engine.'
52+
53+
- name: Compile function
54+
env:
55+
WOLFRAMENGINE_INSTALLATION_DIRECTORY: '${{ runner.temp }}\${{ env.WOLFRAMENGINE_INSTALLATION_SUBDIRECTORY }}'
56+
WOLFRAMINIT: "-pwfile !cloudlm.wolfram.com -entitlement ${{ secrets.WOLFRAM_LICENSE_ENTITLEMENT_ID }}"
57+
run: |
58+
$env:Path += ';${{ env.WOLFRAMENGINE_INSTALLATION_DIRECTORY }}\'
59+
60+
wolfram -script ./compile.wls
61+
62+
- name: Archive compiled libraries
63+
uses: actions/upload-artifact@v2
64+
with:
65+
name: CompiledFunctionLibraries-${{ env.WOLFRAM_SYSTEM_ID }}
66+
path: |
67+
compiled/
68+
if-no-files-found: error
69+
70+
FunctionCompile-MacOSX-x86-64:
71+
runs-on: macos-latest
72+
env:
73+
WOLFRAM_SYSTEM_ID: MacOSX-x86-64
74+
WOLFRAMENGINE_CACHE_KEY: WolframEngine-A
75+
WOLFRAMENGINE_INSTALLATION_DIRECTORY: "/Applications/Wolfram Engine.app"
76+
steps:
77+
- name: Check out repository
78+
uses: actions/checkout@v2
79+
80+
- name: Cache/restore Wolfram Engine install
81+
id: cache-restore
82+
uses: actions/cache@v2
83+
with:
84+
path: ${{ env.WOLFRAMENGINE_INSTALLATION_DIRECTORY }}
85+
key: wolframengine-${{ env.WOLFRAM_SYSTEM_ID }}-${{ env.WOLFRAMENGINE_CACHE_KEY }}
86+
87+
- name: Install Wolfram Engine
88+
if: steps.cache-restore.outputs.cache-hit != 'true'
89+
run: |
90+
echo 'Installing Wolfram Engine...'
91+
brew install --cask wolfram-engine
92+
echo 'Installed Wolfram Engine.'
93+
94+
- name: Compile function
95+
env:
96+
WOLFRAMENGINE_EXECUTABLES_DIRECTORY: "${{ env.WOLFRAMENGINE_INSTALLATION_DIRECTORY }}/Contents/Resources/Wolfram Player.app/Contents/MacOS"
97+
WOLFRAMSCRIPT_ENTITLEMENTID: ${{ secrets.WOLFRAM_LICENSE_ENTITLEMENT_ID }}
98+
WOLFRAMSCRIPT_KERNELPATH: "${{ env.WOLFRAMENGINE_INSTALLATION_DIRECTORY }}/Contents/MacOS/WolframKernel"
99+
run: |
100+
export PATH="${{ env.WOLFRAMENGINE_EXECUTABLES_DIRECTORY }}:$PATH"
101+
102+
wolframscript -debug -verbose -script ./compile.wls
103+
104+
- name: Archive compiled libraries
105+
uses: actions/upload-artifact@v2
106+
with:
107+
name: CompiledFunctionLibraries-${{ env.WOLFRAM_SYSTEM_ID }}
108+
path: |
109+
compiled/
110+
if-no-files-found: error
111+
112+
FunctionCompile-Linux-x86-64:
113+
runs-on: ubuntu-latest
114+
container:
115+
image: wolframresearch/wolframengine:latest
116+
options: --user root
117+
env:
118+
WOLFRAM_SYSTEM_ID: Linux-x86-64
119+
steps:
120+
- name: Check out repository
121+
uses: actions/checkout@v2
122+
123+
- name: Install build tools
124+
run: |
125+
apt-get -y update
126+
apt-get -y install build-essential
127+
128+
- name: Compile function
129+
env:
130+
WOLFRAMSCRIPT_ENTITLEMENTID: ${{ secrets.WOLFRAM_LICENSE_ENTITLEMENT_ID }}
131+
run: |
132+
wolframscript -script ./compile.wls
133+
134+
- name: Archive compiled libraries
135+
uses: actions/upload-artifact@v2
136+
with:
137+
name: CompiledFunctionLibraries-${{ env.WOLFRAM_SYSTEM_ID }}
138+
path: |
139+
compiled/
140+
if-no-files-found: error

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
compiled/

compile.wls

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env wolframscript
2+
3+
$sourceDirectory = "functions"
4+
$sourceFileExtensionPattern = "wl" | "m" | "wxf" | "mx"
5+
6+
$buildDirectory = "compiled"
7+
Quiet@CreateDirectory[$buildDirectory]
8+
9+
$platformLibraryExtension = $OperatingSystem // Replace[{
10+
"Windows" -> "dll",
11+
"MacOSX" -> "dylib",
12+
"Unix" -> "so",
13+
_ -> None
14+
}]
15+
If[
16+
(* if the $OperatingSystem is not a known value *)
17+
!StringQ[$platformLibraryExtension],
18+
(* then print a failure message and exit *)
19+
Print@TemplateApply[
20+
"ERROR: Unsupported $OperatingSystem \"`1`\"",
21+
$OperatingSystem
22+
];
23+
Exit[1]
24+
]
25+
26+
functionPathsToCompile = FileNames[
27+
__ ~~ "." ~~ $sourceFileExtensionPattern,
28+
$sourceDirectory
29+
]
30+
31+
If[
32+
(* if no function files were found *)
33+
Length[functionPathsToCompile] === 0,
34+
(* then print a failure message and exit *)
35+
Print@TemplateApply[
36+
"ERROR: No function source files found in directory \"`1`\"",
37+
$sourceDirectory
38+
];
39+
Exit[1]
40+
]
41+
42+
Print["Function(s) to compile: ", functionPathsToCompile]
43+
44+
compilationResults = functionPathsToCompile // Map[
45+
Function[functionPath, Module[{
46+
compiledFunctionPath = FileNameJoin[{
47+
$buildDirectory,
48+
FileBaseName[functionPath] <> "." <> $platformLibraryExtension
49+
}],
50+
functionExpression,
51+
compilationResult
52+
},
53+
54+
(* import function *)
55+
Print@TemplateApply["Importing function from '`1`'...", {functionPath}];
56+
57+
functionExpression = Import[functionPath];
58+
If[
59+
(* if the import failed *)
60+
FailureQ[functionExpression],
61+
(* then print a failure message and exit *)
62+
Print@TemplateApply["ERROR: failed to import function from '`1`'.", {functionPath}];
63+
Exit[1]
64+
];
65+
66+
(* compile function *)
67+
Print@TemplateApply[
68+
"Compiling function from '`1`' to '`2`'...",
69+
{functionPath, compiledFunctionPath}
70+
];
71+
72+
compilationResult = FunctionCompileExportLibrary[compiledFunctionPath, functionExpression];
73+
If[
74+
(* if FunctionCompileExportLibrary didn't return a file path *)
75+
!StringQ[compilationResult],
76+
(* then print a failure message and exit *)
77+
Print@TemplateApply[
78+
"ERROR: failed to compile function from '`1`' to '`2`'.",
79+
{functionPath, compiledFunctionPath}
80+
];
81+
Print["FunctionCompileExportLibrary returned:"];
82+
Echo[compilationResult];
83+
Exit[1]
84+
];
85+
86+
Print@TemplateApply[
87+
"Successfully function from '`1`' to '`2`'.",
88+
{functionPath, compiledFunctionPath}
89+
];
90+
91+
compilationResult
92+
]]
93+
]
94+
95+
Print@TemplateApply["Successfully compiled `1` function(s)!", Length[compilationResults]]
96+
97+
Exit[0]

functions/addone.wl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(*
2+
In[1]:= func[42]
3+
Out[1]= 43
4+
*)
5+
6+
Function[Typed[arg, "MachineInteger"], arg + 1]

functions/range.wl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(*
2+
In[1]:= func[20]
3+
Out[1]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
4+
*)
5+
6+
Function[Typed[len, "MachineInteger"], Table[i, {i, len}]]

0 commit comments

Comments
 (0)