swiftmoduleenvironment-variablestilde-expansionmodule-map

Can I use environment variables or tilde in module.modulemap?


My module.modulemap file looks like this:

module CompanyInternalSDK {
    header "~/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h"
    export *
}

However, I get this error:

/Users/username/Path/To/Project/CompanyInternalSDK/module.modulemap:2:12: error: header '~/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h' not found
    header "~/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h"
           ^

It compiles just fine when I use the absolute path without the tilde, but since this will be distributed like this to all developers, I want to use the tilde. Is there any way to make this work correctly?


I also tried to use an environment variable in the header string, but that didn't work either:

module CompanyInternalSDK {
    header "${HOME}/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h"
    export *
}
/Users/username/Path/To/Project/CompanyInternalSDK/module.modulemap:2:12: error: header '${HOME}/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h' not found
    header "${HOME}/Company/CompanyInternalSDK.framework/Headers/CompanyInternalSDK.h"
           ^

Solution

  • No, the modulemap syntax does not expand tildes or environment variables. It ultimately just expects to stat the path you gave it, and if no file's there, it'll gripe.

    However, it's standard to use relative paths in module maps. The lexer respects this, and all the module map docs demonstrate this. In the common case where your module map file is colocated with your library and installed alongside it, this should suffice to properly resolve the paths.