Skip to content

Commit 0649fdc

Browse files
committed
Get Makefile working
This leverages julia#59108 to generate a log file with the information needed to create a language binding. As that PR is not yet merged, this may be subject to change. This appears to get things working up through trimming, at which point there are many verifier errors that need to be resolved.
1 parent 3215f27 commit 0649fdc

File tree

6 files changed

+33
-291
lines changed

6 files changed

+33
-291
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/Manifest.toml
55
/docs/Manifest.toml
66
/docs/build/
7+
/language_wrappers/Manifest.toml
8+
/language_wrappers/bindinginfo_libNMFMerge.log

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

language_wrappers/Makefile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ endif
1313
#=============================================================================
1414
# location of test source
1515
SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
16-
PKGDIR := $(dir $(SRCDIR))
16+
PKGDIR := $(abspath $(dir $(SRCDIR)))
1717
JULIAHOME := $(abspath $(JULIA)/../..)
18-
BUILDSCRIPT := $(BIN)/../share/julia/juliac-buildscript.jl
18+
# BUILDSCRIPT := $(BIN)/../share/julia/juliac-buildscript.jl
1919
# include $(JULIAHOME)/Make.inc
2020

2121
# FIXME
@@ -26,24 +26,28 @@ EXE := $(suffix $(abspath $(JULIA)))
2626

2727
# get compiler and linker flags. (see: `contrib/julia-config.jl`)
2828
JULIA_CONFIG := $(JULIA) -e 'include(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "julia-config.jl"))' --
29+
JULIA_LIBDIR := $(shell $(JULIA) -e 'println(joinpath(Sys.BINDIR, "..", "lib"))' --)
2930
CPPFLAGS_ADD :=
3031
CFLAGS_ADD = $(shell $(JULIA_CONFIG) --cflags)
3132
LDFLAGS_ADD = -lm $(shell $(JULIA_CONFIG) --ldflags --ldlibs) -ljulia-internal
3233

34+
# get the JuliaC build script
35+
JULIAC_BUILDSCRIPT := $(shell $(JULIA) -e 'print(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "juliac", "juliac-buildscript.jl"))')
36+
3337
#=============================================================================
3438

35-
release: NMFMerge-jl.$(SHLIB_EXT)
39+
release: libNMFMerge-o.a
3640

37-
NMFMerge-jl.$(SHLIB_EXT): $(PKGDIR)/src/NMFMerge.jl $(BUILDSCRIPT)
38-
$(JULIA) -t 1 -J $(BIN)/../lib/julia/sys.$(SHLIB_EXT) --project --startup-file=no --history-file=no --output-incremental=no --strip-ir --strip-metadata --experimental --trim $(BUILDSCRIPT) $(SRCDIR)/lib.jl --output-lib NMFMerge-jl.so
41+
$(BIN)/libNMFMerge-o.a: $(PKGDIR)/language_wrappers/lib.jl $(JULIAC_BUILDSCRIPT)
42+
$(JULIA) -t 1 -J $(JULIA_LIBDIR)/julia/sys.$(SHLIB_EXT) --startup-file=no --history-file=no --project=$(PKGDIR)/language_wrappers/ --output-o $@ --output-incremental=no --strip-ir --strip-metadata --experimental --trim $(JULIAC_BUILDSCRIPT) $< --output-lib true $(BIN)/bindinginfo_libNMFMerge.log
3943

40-
check: hello$(EXE) basic_jll$(EXE) # FIXME
41-
$(JULIA) --depwarn=error $(SRCDIR)/../runtests.jl $(SRCDIR)/trimming
44+
# check: $(BIN)/libNMFMerge$(EXE)
45+
# $(JULIA) --depwarn=error $(SRCDIR)/trimming.jl $<
4246

43-
clean: # FIXME
44-
-rm -f hello$(EXE) basic_jll$(EXE) init.o hello.o basic_jll.o
47+
clean:
48+
-rm -f $(BIN)/libNMFMerge-o.a $(BIN)/bindinginfo_libNMFMerge.log
4549

46-
.PHONY: release clean check
50+
.PHONY: release clean
4751

4852
# Makefile debugging trick:
4953
# call print-VARIABLE to see the runtime value of any variable

language_wrappers/Manifest.toml

Lines changed: 0 additions & 277 deletions
This file was deleted.

language_wrappers/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[deps]
22
NMFMerge = "9cc52eda-dfaf-4e21-aae3-9f26bed153a3"
3+
4+
[sources]
5+
NMFMerge = {path = ".."}

language_wrappers/lib.jl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@ struct ReturnValue
88
objvalue::Float64
99
end
1010

11-
Base.@ccallable function nmfmerge_inplace(Wout::Matrix{Float64}, Hout::Matrix{Float64}, X::Matrix{Float64}, ncomponents::Int32, tol::Float64, maxiter::Int32)::ReturnValue
11+
struct CMatrix{T} <: AbstractMatrix{T}
12+
data::Ptr{T}
13+
rows::Int32
14+
cols::Int32
15+
end
16+
17+
Base.@ccallable function nmfmerge_inplace(Wout::CMatrix{Float64}, Hout::CMatrix{Float64}, X::CMatrix{Float64}, ncomponents::Int32, tol::Float64, maxiter::Int32)::ReturnValue
18+
Wout.rows == X.rows || throw(ArgumentError("Wout and X must have the same number of rows"))
19+
Hout.cols == X.cols || throw(ArgumentError("Hout and X must have the same number of columns"))
20+
W, H, X = unsafe_wrap(Array, Wout.data, (Wout.rows, Wout.cols)),
21+
unsafe_wrap(Array, Hout.data, (Hout.rows, Hout.cols)),
22+
unsafe_wrap(Array, X.data, (X.rows, X.cols))
1223
result = nmfmerge(X, ncomponents; tol_final=tol, maxiter)
13-
Wout .= result.W
14-
Hout .= result.H
24+
W .= result.W
25+
H .= result.H
1526
return ReturnValue(result.niters, result.converged, result.objvalue)
1627
end
1728

0 commit comments

Comments
 (0)