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

[feature] Symlink Imports #7030

Closed
1 task done
UnderSampled opened this issue May 15, 2020 · 4 comments
Closed
1 task done

[feature] Symlink Imports #7030

UnderSampled opened this issue May 15, 2020 · 4 comments

Comments

@UnderSampled
Copy link

When using an editable package, if that package is built as a shared library, then imports of the runtime binaries will become stale. This requires conan imports to be run manually whenever the editable is rebuilt, against the stated intention of the editables feature.
If editable imports were made as symlinks rather than copies, that would be sufficient in most cases to avoid running conan imports regularly.

A proposed feature would be to include a --symlink option to the conan imports command (and expose this on conan install as well).

An alternative would be to automatically use symlinks for editable packages, if the environment supports them. This could eventually extend to even non-editable packages if desired.

A workaround was suggested in the channel on cpplang slack:

def imports(self):
    # Import the files
    self.copy("*.so*", dst="lib", root_package="your-dependency-package-name", ignore_case=False, keep_path=False)
    with tools.chdir(os.path.join(self.imports_folder, "lib")):
        for dynamic_lib in glob.iglob("*.so.*", recursive=True):
            lib_symlink = "{}.so".format(dynamic_lib.split(".so")[0])  # basename
                if os.path.exists(lib_symlink):
                    os.remove(lib_symlink)
                self.output.info("Creating symlink {} --> {}".format(lib_symlink, dynamic_lib))

This is not desirable, as it requires adding to the conanfile.py of any package which might be worked on in this way. It also forces the use of a conanfile.py instead of a conanfile.txt.

@jgsogo
Copy link
Contributor

jgsogo commented May 22, 2020

Hi!

First of all, I would think twice if using imports is the way to go. Usually it is enough to have the paths to your dependencies and link against them and, if needed, gather all the binaries from the dependency tree using the deploy generator.

If you can avoid using imports, then editables with a layout file should be able to work: the libraries would be used from the place where they are generated, no need to copy or link them to a different place.

Are imports really necessary in your scenario?

@jgsogo jgsogo self-assigned this May 22, 2020
@UnderSampled
Copy link
Author

We use imports directly according to the purpose described in the documentation: https://docs.conan.io/en/1.19/using_packages/conanfile_txt.html#imports

We have many runtime dependencies such as shared libraries, runtime-loaded libraries, config-files, and even executables (yes, there are some legacy decisions that have stuck with us). As stated in the document, "In Windows and OSX, the simplest approach is to copy the shared libraries to the executable folder, so they are found by the executable, without having to modify the path." This is the approach we've taken, and it's fit our needs precisely.

Before we switched to Conan for package management, our CMake build system actually had some custom logic to copy the shared libraries of dependencies in order to automatically run software tests on Windows. I was very happy to see Conan had thought out a better way to handle that exact need with imports.

So, we extensively use imports for it's designed purpose during development, and would greatly benefit from better integration with editables.

@jgsogo jgsogo added this to To do in Packages in editable mode via automation May 25, 2020
@jgsogo
Copy link
Contributor

jgsogo commented May 26, 2020

Hi! I'm still thinking about this. I know executing things from CMake is a little bit hard when you need shared libraries, this is an issue we have faced in some of our examples (conan-io/examples#17) and also in the protobuf recipe right now (conan-io/conan-center-index#1179). I need to revisit both of them to see how it goes.

For the general use-case, conan create ..., creating symlinks here would introduce another problem to all the ones we have right now related to symlinks. But here we are talking about conan imports ... which is something used in the local workflow, so the user should be aware.

Adding --symlinks to this command would solve your issue and it will introduce a new problem only if the package is created following the local workflow (with the export-pkg). Nevertheless I think this shouldn't be a blocker.

For workspaces, it will continue to be a problem, but the workspaces feature is something we need to work again.

Let's add conan imports --symlinks and it will create symlinks for all the imported files.

@memsharded
Copy link
Member

The imports() method has been made legacy in Conan 1.X by explicit copy() in generate() and removed in Conan 2.0. Closing this ticket, please create new tickets as necessary, thanks!

@memsharded memsharded closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2024
Packages in editable mode automation moved this from To do to Done Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

3 participants