Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCH issues compiling a package after internal installation of CmdStan on Mac OS #9

Closed
wlandau opened this issue Aug 12, 2023 · 1 comment
Assignees

Comments

@wlandau
Copy link
Owner

wlandau commented Aug 12, 2023

Running R 4.3.0 on an M2 Mac with OS 13.5, I am running into PCH issues trying to compile a package after internal installation of CmdStan. First, I install instantiate with the "internal" method where CmdStan is compiled inside the package file system.

Sys.setenv(CMDSTAN_INSTALL = "internal")
remotes::install_github('wlandau/instantiate")
library(instantiate)
stan_cmdstan_path() # CmdStan is inside the package file system
#> [1] "/Users/CENSORED/projects/instantiate/inst/cmdstan/cmdstan-2.32.2"

Then I create an example package with a Stan file inside.

path <- "example"
stan_package_create(path = path)
stan_package_configure(path = path)
fs::dir_tree(path)
#> example
#> ├── DESCRIPTION
#> ├── NAMESPACE
#> ├── NOTICE
#> ├── R
#> │   ├── model.R
#> │   └── package.R
#> ├── cleanup
#> ├── cleanup.win
#> ├── configure
#> ├── configure.win
#> ├── example.Rproj
#> ├── inst
#> │   └── stan
#> │       └── bernoulli.stan
#> └── man
#>     ├── example-package.Rd
#>     └── run_bernoulli_model.Rd

Compilation fails:

install.packages(
  pkgs = path,
  lib = temporary_library,
  type = "source",
  repos = NULL
)
#> * installing *source* package ‘example’ ...
#> ** using staged installation
#> Running make \
#>   /var/folders/4v/vh7xp8553lsbl49svl48g7p00000gp/T/RtmpUAgcPM/model-b6944df95fca \
#>   "STANCFLAGS +=  --name='bernoulli_model'"
#> 
#> --- Translating Stan model to C++ code ---
#> bin/stanc --name='bernoulli_model' --o=/var/folders/4v/vh7xp8553lsbl49svl48g7p00000gp/T/RtmpUAgcPM/model-b6944df95fca.hpp /var/folders/4v/vh7xp8553lsbl49svl48g7p00000gp/T/RtmpUAgcPM/model-b6944df95fca.stan
#> 
#> --- Compiling, linking C++ code ---
#> clang++ -arch arm64 -std=gnu++17 -falign-functions=64 -Wall -g -O2 -falign-functions=1 -Wno-deprecated-declarations -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -I/opt/R/arm64/include    -DBOOST_DISABLE_ASSERTS          -c -include-pch stan/src/stan/model/model_header.hpp.gch -x c++ -o /var/folders/4v/vh7xp8553lsbl49svl48g7p00000gp/T/RtmpUAgcPM/model-b6944df95fca.o /var/folders/4v/vh7xp8553lsbl49svl48g7p00000gp/T/RtmpUAgcPM/model-b6944df95fca.hpp
#> error: Default alignment for functions differs in PCH file vs. current file
#> error: Default alignment for functions differs in PCH file vs. current file
#> 
#> 1 error generated.
#> make: *** [/var/folders/4v/vh7xp8553lsbl49svl48g7p00000gp/T/RtmpUAgcPM/model-b6944df95fca] Error 1
#> 1 error generated.
#> make: *** [/var/folders/4v/vh7xp8553lsbl49svl48g7p00000gp/T/RtmpUAgcPM/model-b6944df95fca] Error 1
#> 
#> Error: An error occured during compilation! See the message above for more information.
#> In addition: Warning message:
#> CmdStan's precompiled header (PCH) files may need to be rebuilt.
#> If your model failed to compile please run rebuild_cmdstan().
#> If the issue persists please open a bug report. 
#> Execution halted
#> Could not compile Stan models.
#> ERROR: configuration failed for package ‘example’
#> * removing ‘/Users/C240390/projects/instantiate/library/example’
#> Warning in install.packages :
#>   installation of package ‘example’ had non-zero exit status

Manually rebuilding CmdStan makes it work, but having to do that defeats the purpose of instantiate. This is definitely related to #1.

@wlandau wlandau self-assigned this Aug 12, 2023
@wlandau
Copy link
Owner Author

wlandau commented Aug 12, 2023

Indeed, commenting out the manually-inserted CXXFLAGS="$CXXFLAGS -falign-functions=1" line in configure made it work. But omitting it broke compilation before. All this makes #1 really important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant