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

Introduce ra_proc_macro_srv #3800

Merged
merged 2 commits into from
Apr 3, 2020

Conversation

edwin0cheng
Copy link
Member

This PR add preliminary for server side of proc macro :

  1. Add crate setup
  2. IO for server side


[dependencies]
ra_tt = { path = "../ra_tt" }
ra_mbe = { path = "../ra_mbe" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matklad We need mbe here for parsing string to ra_tt::Token which is used for lib_proc_macro bridge api.

@edwin0cheng
Copy link
Member Author

edwin0cheng commented Apr 1, 2020

CI failed in deny_c for libloading crate. Um...

@Veetaha
Copy link
Contributor

Veetaha commented Apr 1, 2020

Maybe use dlopen() and LoadLibrary() directly?

@bjorn3
Copy link
Member

bjorn3 commented Apr 1, 2020

The C code is used for a lock around dlerror. This was necessary to fix nagisa/rust_libloading#32. It can't be written in C, as it uses a weak global variable to store the lock in. (rust-lang/rust#29603) This way multiple versions of libloading can use the same lock without conflicts.

https://github.com/nagisa/rust_libloading/blob/953681d3958c04d735b30a1170b3fa6fc8ed7ab0/src/os/unix/global_static.c

#include <pthread.h>
#include <stdlib.h>

pthread_mutex_t __attribute__((weak)) rust_libloading_dlerror_mutex = PTHREAD_MUTEX_INITIALIZER;

void __attribute__((weak))
rust_libloading_dlerror_mutex_lock(void)
{
    if (pthread_mutex_lock(&rust_libloading_dlerror_mutex) != 0) {
        abort();
    }
}

void __attribute__((weak))
rust_libloading_dlerror_mutex_unlock(void)
{
    if (pthread_mutex_unlock(&rust_libloading_dlerror_mutex) != 0) {
        abort();
    }
}

@edwin0cheng
Copy link
Member Author

edwin0cheng commented Apr 1, 2020

Another reason : We would need to get proc-macro symbols from these dylibs in different platform (linux, mac, windows). and using libloading to handle them fairly easily.

@matklad
Copy link
Member

matklad commented Apr 1, 2020

Maybe use dlopen() and LoadLibrary() directly?

This is exactly the case where depending on 3d-party lib can save us a royal amount of pain :)

@bjorn3
Copy link
Member

bjorn3 commented Apr 1, 2020

Maybe deny_c can become a script that checks if it's parent process is the build script for libloading and only execute the c compiler in that case?

@flodiebold
Copy link
Member

Maybe we should have a cargo feature for enabling/disabling proc macro support, and could then do the deny_c check without that?

@edwin0cheng
Copy link
Member Author

edwin0cheng commented Apr 1, 2020

Maybe we should have a cargo feature for enabling/disabling proc macro support, and could then do the deny_c check without that?

That deny_c check is defined in environment variable, so we would have to separate two CI check action to support it. Anyway, we have to change our CI for the proc-macro-srv executable to be included in the release package.

@matklad
Copy link
Member

matklad commented Apr 1, 2020 via email

@edwin0cheng edwin0cheng mentioned this pull request Apr 3, 2020
@edwin0cheng edwin0cheng force-pushed the introduce-proc-macro-srv branch from f75afe2 to 84fb9b4 Compare April 3, 2020 11:01
@matklad
Copy link
Member

matklad commented Apr 3, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 3, 2020

@bors bors bot merged commit 1a8779b into rust-lang:master Apr 3, 2020
@edwin0cheng edwin0cheng deleted the introduce-proc-macro-srv branch April 3, 2020 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants