Building CmdStan executables from arbitrary paths

@mitzimorris, I was thinking about what you’re trying to do for CmdStanPy and thought we could discuss here.

We don’t need make to build the executable. make has the restriction that doesn’t allow spaces in make targets (the executable to build).

We can have our makefiles produce the C++ compiler invocation that will compile an executable. If we had that, we can have any script call the compiler directly to build an executable. Think it’s worth pursuing?

1 Like

I just use ‘make -C’ in my R wrapper and it seems to work fine but something more standard would be great.

what does make -C do? it doesn’t do anything in my makefiles.

It’s a make option (also available in git) that makes the command pretend to run in the provided directory. My package installs cmdstan in a configured location and copies the model file to a working directory. Then runs make -C $CMDSTAN_DIR $WORK_DIR/$MODEL_NAME

Works fine…

K

Line 55 here: https://github.com/sakrejda/stannis/blob/rcmdstan-simplify/R/cmdstan-compile.R

ah… but it won’t work if there’s a space in either the $WORK_DIR or $MODEL_NAME.

Quoting works fine…

Anyway, main point was: yes please provide the required invocation and there’s no reason make has to be the one calling the compiler!

What?!?! What version of make are you using? And what do you use to escape spaces?

D’oh, I’m right about the shell stuff but not make itself. The package controls where cmdstan is installed although the user could change it to somewhere with spaces, I haven’t tested that. I didn’t even think of spaces in the filename being passed on to make but that could be worked around by copying the model to a standard filename and copying the binary back to the work directory. I’m not sure if the paths used by -C are used directly in the makefile…

Cool. Got it… I’ll make an issue… I’m not sure exactly what repo it should be in. Also, is there a common make target for these types of things?

How’s a target like compile_info? I’m borrowing from mpicxx. They have an option for -compile_info.

1 Like

Anything that makes fewer things to remember

did you see the discussion here? Posix style path to make command · Issue #31 · stan-dev/cmdstanpy · GitHub

No. Not until you pointed me there.

That still doesn’t help with paths spaces in file names. What is it I’m supposed to gain from that discussion?

Edit: whoops. paths -> spaces.

I thought there might be hooks in Pythons’ pathlib module, but after more reading, not possible.

1 Like

I just put up a PR in CmdStan: https://github.com/stan-dev/cmdstan/pull/708

I realized that’s the only place where it’s really applicable. Stan doesn’t generate executables and we can control the test model locations so there are no spaces. Math also doesn’t generate executables. So it’s only in CmdStan.

I don’t know if there’s an easy way to pipe that output from make. If there’s a more convenient form, we can fix it.

Summary: if you use CmdStan branch feature/issue-707-compile_info you can type:

make compile_info

and it will show the C++ compiler configuration to compile + link a Stan executable. The user will have to provide 2 things to it:

  1. the location of the bin/stanc generated .hpp file by adding -include <header>.hpp
  2. the output location of the executable (default will be a.out on linux-like OSes) by adding -o <executable>
1 Like

Nice! I was rewriting that compilation function anyway, lemme see if I can go from this branch

1 Like