From patchwork Tue Oct 8 23:19:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 13827195 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 178F5218584 for ; Tue, 8 Oct 2024 23:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429582; cv=none; b=t1JNNWxixpUAF2XGIvJUm6Y37O+2MRcUX+4gn/oa7lLuFVb2fvO1iJtMq5IA9s49kIc6RLtYnuhZiBC1C9fbwRJvR3X9TnhmH2br6uVZinksnBBByqVRIsoa6KSWMgVrLSIq/2SA6sCyReL1oAAmm6pCPlnQh40dKRWX02B5WXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429582; c=relaxed/simple; bh=JBS9SnWJ3U6atlNJMVIMcEWrsoqzH/ajDtHJ3Xzphcs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Qc7J1KM3QUemPJ7F+odwUq+BMfdZbGNsn+wYmU4fIGBtTXTG9l7yJ/sM/OaT4ueJDDgeU82adv2bVLAEfeeApy7yjSS6oweoOlg/6QmKRoE2SvoOhre3SiOHeLC5tw2t85+2w4kNIM9wqroQoKSnDJMd4cuF9QT2wGYhzw4ep3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=F7aysJjh; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F7aysJjh" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3204db795so5261107b3.2 for ; Tue, 08 Oct 2024 16:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728429580; x=1729034380; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4B4dEWv8y9Qd3S1MimW5v7zVo47XrMO3kEwqW/kDQMo=; b=F7aysJjhvgZ8MyBjJCsTnpjU8nfvR782S31ajG3i4RtPnUkU7zchpozCacpr8dI9al u99lQwU+SD2WQ2Yi0BxSExsL/J/Hbi4TdO7l/2CKyYNUYAJXV2qhui8FLyiMMFNlINqC 6X8Q2s22vf+Za5KaFVk7BGb4NX7YY4oWwYGkzD7Rsia3UBbgNzOON76F3bQ45fSq92Xa qftG83N7UKmA2m/9uMk0DIHhYGi0BTX+NdcPQ4sgyG2gurjFQiZRL9IkA00e9d64OUUk UJj+gAcXKmI5EApgigASmrgES/EdWbSMXrfylxDueS4UrRUCYy3tz7zWfAOiu09/doV4 imCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728429580; x=1729034380; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4B4dEWv8y9Qd3S1MimW5v7zVo47XrMO3kEwqW/kDQMo=; b=ELj8BSuWu0KfUHjlg/YqE/ctN5O6U2vqHHJ9xa/crgTG4bQE4ymU7IG5uyO5V5VBPA 1kkaEqZjVyLMScOEG3bI42zrltyl/0sFxMq0HzX6iss/FIlJtQSoxJEnEm/GR/yBgmFs ZEf1CYFvhj0kM7BY8jWqAaapyJVE5hZ581Sxx1kBaSxTSSeuZsN9S/YIa3AhvZ3IuS2b cAs2JGKo18Zj3NRBcpBlLzQSxPyFtJfit7nWu+1zZ7fZknlyg5BOy5WmGhHDNnmvXTID /0whmYWYHmCuY1Ow0kZdKDoNDaInIC0TDyQsMdeMyLqqvr5y1DZZaFxKJRsqAFX/CiCS +D2A== X-Gm-Message-State: AOJu0YzTnVLfE0yD1SBW03YgrvhhJBQFfu/prId4eXFqsULxYOm60pUD XIczp+nDZ5cdYyu5S0RhMUZuAYPhzppAuW8+rozfWHZDtlO3NcS0mKjkyiKIha/7P3AJaT/Vsoe H5lY40lr7WGpBSJWtiQrzEEFkDDKq3jrxhwAiYEjZz8hZqCCYdhna7YmYlL+GMnaE1xK5riAFyh qo3oKR/D6b8S2lGZiO0IHGRfhG57hJQu3+jq6ZmDM= X-Google-Smtp-Source: AGHT+IGFD59NCCleS6BX2GYgT7iFovjLMdbeGPJiXYBhmViUXj/+6TpPdGFZ+Jb6WucYSDQAYwpvSPv1MShcSg== X-Received: from lunarfall.svl.corp.google.com ([2620:15c:2d3:204:7c00:8752:4498:cc1b]) (user=steadmon job=sendgmr) by 2002:a05:690c:460d:b0:6db:89f0:b897 with SMTP id 00721157ae682-6e3221683d8mr12047b3.4.1728429578861; Tue, 08 Oct 2024 16:19:38 -0700 (PDT) Date: Tue, 8 Oct 2024 16:19:31 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <1ae14207f69af3d1c6fe19dfd779062a69f16122.1728429158.git.steadmon@google.com> Subject: [PATCH v4 1/5] common-main: split init and exit code into new files From: Josh Steadmon To: git@vger.kernel.org Cc: calvinwan@google.com, spectral@google.com, emilyshaffer@google.com, emrass@google.com, gitster@pobox.com, mh@glandium.org, sandals@crustytoothpaste.net, ps@pks.im, sunshine@sunshineco.com, phillip.wood123@gmail.com, allred.sean@gmail.com Currently, object files in libgit.a reference common_exit(), which is contained in common-main.o. However, common-main.o also includes main(), which references cmd_main() in git.o, which in turn depends on all the builtin/*.o objects. We would like to allow external users to link libgit.a without needing to include so many extra objects. Enable this by splitting common_exit() and check_bug_if_BUG() into a new file common-exit.c, and add common-exit.o to LIB_OBJS so that these are included in libgit.a. This split has previously been proposed ([1], [2]) to support fuzz tests and unit tests by avoiding conflicting definitions for main(). However, both of those issues were resolved by other methods of avoiding symbol conflicts. Now we are trying to make libgit.a more self-contained, so hopefully we can revisit this approach. Additionally, move the initialization code out of main() into a new init_git() function in its own file. Include this in libgit.a as well, so that external users can share our setup code without calling our main(). [1] https://lore.kernel.org/git/Yp+wjCPhqieTku3X@google.com/ [2] https://lore.kernel.org/git/20230517-unit-tests-v2-v2-1-21b5b60f4b32@google.com/ Signed-off-by: Josh Steadmon --- Makefile | 2 ++ common-exit.c | 26 ++++++++++++++++ common-init.c | 63 ++++++++++++++++++++++++++++++++++++++ common-init.h | 6 ++++ common-main.c | 83 ++------------------------------------------------- 5 files changed, 99 insertions(+), 81 deletions(-) create mode 100644 common-exit.c create mode 100644 common-init.c create mode 100644 common-init.h diff --git a/Makefile b/Makefile index 3eab701b10..7caeb3c872 100644 --- a/Makefile +++ b/Makefile @@ -979,6 +979,8 @@ LIB_OBJS += combine-diff.o LIB_OBJS += commit-graph.o LIB_OBJS += commit-reach.o LIB_OBJS += commit.o +LIB_OBJS += common-exit.o +LIB_OBJS += common-init.o LIB_OBJS += compat/nonblock.o LIB_OBJS += compat/obstack.o LIB_OBJS += compat/terminal.o diff --git a/common-exit.c b/common-exit.c new file mode 100644 index 0000000000..1aaa538be3 --- /dev/null +++ b/common-exit.c @@ -0,0 +1,26 @@ +#include "git-compat-util.h" +#include "trace2.h" + +static void check_bug_if_BUG(void) +{ + if (!bug_called_must_BUG) + return; + BUG("on exit(): had bug() call(s) in this process without explicit BUG_if_bug()"); +} + +/* We wrap exit() to call common_exit() in git-compat-util.h */ +int common_exit(const char *file, int line, int code) +{ + /* + * For non-POSIX systems: Take the lowest 8 bits of the "code" + * to e.g. turn -1 into 255. On a POSIX system this is + * redundant, see exit(3) and wait(2), but as it doesn't harm + * anything there we don't need to guard this with an "ifdef". + */ + code &= 0xff; + + check_bug_if_BUG(); + trace2_cmd_exit_fl(file, line, code); + + return code; +} diff --git a/common-init.c b/common-init.c new file mode 100644 index 0000000000..5cc73f058c --- /dev/null +++ b/common-init.c @@ -0,0 +1,63 @@ +#define USE_THE_REPOSITORY_VARIABLE + +#include "git-compat-util.h" +#include "common-init.h" +#include "exec-cmd.h" +#include "gettext.h" +#include "attr.h" +#include "repository.h" +#include "setup.h" +#include "strbuf.h" +#include "trace2.h" + +/* + * Many parts of Git have subprograms communicate via pipe, expect the + * upstream of a pipe to die with SIGPIPE when the downstream of a + * pipe does not need to read all that is written. Some third-party + * programs that ignore or block SIGPIPE for their own reason forget + * to restore SIGPIPE handling to the default before spawning Git and + * break this carefully orchestrated machinery. + * + * Restore the way SIGPIPE is handled to default, which is what we + * expect. + */ +static void restore_sigpipe_to_default(void) +{ + sigset_t unblock; + + sigemptyset(&unblock); + sigaddset(&unblock, SIGPIPE); + sigprocmask(SIG_UNBLOCK, &unblock, NULL); + signal(SIGPIPE, SIG_DFL); +} + +void init_git(const char **argv) +{ + struct strbuf tmp = STRBUF_INIT; + + trace2_initialize_clock(); + + /* + * Always open file descriptors 0/1/2 to avoid clobbering files + * in die(). It also avoids messing up when the pipes are dup'ed + * onto stdin/stdout/stderr in the child processes we spawn. + */ + sanitize_stdfds(); + restore_sigpipe_to_default(); + + git_resolve_executable_dir(argv[0]); + + setlocale(LC_CTYPE, ""); + git_setup_gettext(); + + initialize_repository(the_repository); + + attr_start(); + + trace2_initialize(); + trace2_cmd_start(argv); + trace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP); + + if (!strbuf_getcwd(&tmp)) + tmp_original_cwd = strbuf_detach(&tmp, NULL); +} diff --git a/common-init.h b/common-init.h new file mode 100644 index 0000000000..3e6db20cae --- /dev/null +++ b/common-init.h @@ -0,0 +1,6 @@ +#ifndef COMMON_INIT_H +#define COMMON_INIT_H + +void init_git(const char **argv); + +#endif /* COMMON_INIT_H */ diff --git a/common-main.c b/common-main.c index 8e68ac9e42..6b7ab077b0 100644 --- a/common-main.c +++ b/common-main.c @@ -1,92 +1,13 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" -#include "exec-cmd.h" -#include "gettext.h" -#include "attr.h" -#include "repository.h" -#include "setup.h" -#include "strbuf.h" -#include "trace2.h" - -/* - * Many parts of Git have subprograms communicate via pipe, expect the - * upstream of a pipe to die with SIGPIPE when the downstream of a - * pipe does not need to read all that is written. Some third-party - * programs that ignore or block SIGPIPE for their own reason forget - * to restore SIGPIPE handling to the default before spawning Git and - * break this carefully orchestrated machinery. - * - * Restore the way SIGPIPE is handled to default, which is what we - * expect. - */ -static void restore_sigpipe_to_default(void) -{ - sigset_t unblock; - - sigemptyset(&unblock); - sigaddset(&unblock, SIGPIPE); - sigprocmask(SIG_UNBLOCK, &unblock, NULL); - signal(SIGPIPE, SIG_DFL); -} +#include "common-init.h" int main(int argc, const char **argv) { int result; - struct strbuf tmp = STRBUF_INIT; - - trace2_initialize_clock(); - - /* - * Always open file descriptors 0/1/2 to avoid clobbering files - * in die(). It also avoids messing up when the pipes are dup'ed - * onto stdin/stdout/stderr in the child processes we spawn. - */ - sanitize_stdfds(); - restore_sigpipe_to_default(); - - git_resolve_executable_dir(argv[0]); - - setlocale(LC_CTYPE, ""); - git_setup_gettext(); - - initialize_repository(the_repository); - - attr_start(); - - trace2_initialize(); - trace2_cmd_start(argv); - trace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP); - - if (!strbuf_getcwd(&tmp)) - tmp_original_cwd = strbuf_detach(&tmp, NULL); + init_git(argv); result = cmd_main(argc, argv); /* Not exit(3), but a wrapper calling our common_exit() */ exit(result); } - -static void check_bug_if_BUG(void) -{ - if (!bug_called_must_BUG) - return; - BUG("on exit(): had bug() call(s) in this process without explicit BUG_if_bug()"); -} - -/* We wrap exit() to call common_exit() in git-compat-util.h */ -int common_exit(const char *file, int line, int code) -{ - /* - * For non-POSIX systems: Take the lowest 8 bits of the "code" - * to e.g. turn -1 into 255. On a POSIX system this is - * redundant, see exit(3) and wait(2), but as it doesn't harm - * anything there we don't need to guard this with an "ifdef". - */ - code &= 0xff; - - check_bug_if_BUG(); - trace2_cmd_exit_fl(file, line, code); - - return code; -} From patchwork Tue Oct 8 23:19:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 13827196 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15FD4218D64 for ; Tue, 8 Oct 2024 23:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429584; cv=none; b=qcUZT4Rr8KY1YJnexg5fx5//izkK9kB0Zh/YBZbiDVhe8lQYSOVt6+h6EaLfTFcq3SiSQubCrS/feNh5yM2oaXF+3+bFSeIiSsu5PpSJoG8TKa3ab/jgH6SUzQv+im8rfaJeGN3gsWufYgS4VoNfqdnE4BtknEa9WBGKyXJ02CU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429584; c=relaxed/simple; bh=gfdRuKxheTm7RHo1fKOG3n9UMT1Vace9S+GlvfSUpG8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jw6IOTKujU1KaUf/PuWFpSqhIhBroVCfuC9/Om73sFWJlpNKEaMMPTqqkwfJCLN8pjSQuQYY1Xp+8skQ6EwKOsM8BfjjZCfRevpMa99S+DS3Y7FrC6r2ArQyhPq/HBzzq5GkMqPLq1d2T9pXMyT/DYm3O7udYvlf+EU5qTxzJTY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fCMyK6KA; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fCMyK6KA" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e22f0be237so106526167b3.1 for ; Tue, 08 Oct 2024 16:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728429581; x=1729034381; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dsgysmtojNP9kjsK9wDZrchmJPKQx0MVM7ms/6JwAIk=; b=fCMyK6KAcTw92jKlT2jYH92sEvnoKrD6gTyOuJXN3Tm+3DM1nxAJPKj06ve5GzApan GQQNe7ggtM1X3odb50Pvbt1n7UNSXMBn0ZxIQIHQSWoZdtDIjManngMpAgD2lwpFzvt5 bh3nJKHNg7wWT9kqvIma26XZMZ3mxITaB2PhjYCW/4V6OuJZcyyeN151wjmS+nLiy1l8 +plzGWxcl3a8bWdUs3JMyW0HB4XfWbHKLCxogbkPsLXG+evHDsI4v894Vx2FdpUhWReZ Oc8VnNQv5QJbiLBUAh+uqOyEt36uQ7ZWDsQMtR3X/d0gH2W80X06Smd98ifXTs8B4yIf Cu3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728429581; x=1729034381; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dsgysmtojNP9kjsK9wDZrchmJPKQx0MVM7ms/6JwAIk=; b=Iclk1sUVLeQEljF6MQyPGjsc+T+O4kkMutTvl6LizXZsG0AMeY9glMq1SZIkJQVD8q UFpHZbPOa9WnYqzAufAAcCQlfmzFgI5NsZ+uLNMCkA7uDZuB5Ouh7FyeqLNuPK2TodV4 qq7KMGbPeO+xBKFCtTAjXK7Pysta60GHgr8o0QsjyifvQ4O9XUsL4cK/TksssGViMorN 1a2O+XaVF5AdDhW+wk9h3+jOl7M46LwcrGMsg49efXsVOFqmuD/DuK0BdaYzzEx++og3 Jb5Pf1ZlM5w8V8XH2NkpTQLjP5Bz9JzKu2hi0420jXbrHNh9pLXK7v/tnDiwGb+lolUO eN7w== X-Gm-Message-State: AOJu0YwewWko1S3mW+GBc/sR1IVvJH0Sf3KyIYRErSBmhq7v1PGNFVTo 19KTeBLP0niOwfUXkThaRmxPxgXYAi/OqJXZm5KtQMFuw3kiS6xZTTYeE48qcFBmafeFhI3ktkB e+kUMjDVXpNedTEyoClEQyavxMlMAdcqEQyEagDfNiDtU/FD5N/SmW4COSAvzIuiCKy5xxphh4i jRRnww9qe9CSV/D6Zy0NcA35YL2ClZN9OAIVhGOMw= X-Google-Smtp-Source: AGHT+IGYnnfiqV4mCZ787wkGLDQTm91aE1zUzEz4WWZ2bsqFHsNzVumj1GJeFsY4pkaktgFNLubjJGzPc7raIw== X-Received: from lunarfall.svl.corp.google.com ([2620:15c:2d3:204:7c00:8752:4498:cc1b]) (user=steadmon job=sendgmr) by 2002:a05:690c:7690:b0:6e2:1ab6:699a with SMTP id 00721157ae682-6e3224fdd12mr76097b3.7.1728429580946; Tue, 08 Oct 2024 16:19:40 -0700 (PDT) Date: Tue, 8 Oct 2024 16:19:32 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: Subject: [PATCH v4 2/5] libgit-sys: introduce Rust wrapper for libgit.a From: Josh Steadmon To: git@vger.kernel.org Cc: calvinwan@google.com, spectral@google.com, emilyshaffer@google.com, emrass@google.com, gitster@pobox.com, mh@glandium.org, sandals@crustytoothpaste.net, ps@pks.im, sunshine@sunshineco.com, phillip.wood123@gmail.com, allred.sean@gmail.com Introduce libgit-sys, a Rust wrapper crate that allows Rust code to call functions in libgit.a. This initial patch defines build rules and an interface that exposes user agent string getter functions as a proof of concept. This library can be tested with `cargo test`. In later commits, a higher-level library containing a more Rust-friendly interface will be added at `contrib/libgit-rs`. Symbols in libgit can collide with symbols from other libraries such as libgit2. We avoid this by first exposing library symbols in public_symbol_export.[ch]. These symbols are prepended with "libgit_" to avoid collisions and set to visible using a visibility pragma. In build.rs, Rust builds contrib/libgit-rs/libgit-sys/libgitpub.a, which also contains libgit.a and other dependent libraries, with -fvisibility=hidden to hide all symbols within those libraries that haven't been exposed with a visibility pragma. Co-authored-by: Kyle Lippincott Co-authored-by: Calvin Wan Signed-off-by: Calvin Wan Signed-off-by: Kyle Lippincott Signed-off-by: Josh Steadmon --- .gitignore | 1 + Makefile | 13 ++++ contrib/libgit-rs/libgit-sys/Cargo.lock | 69 +++++++++++++++++++ contrib/libgit-rs/libgit-sys/Cargo.toml | 17 +++++ contrib/libgit-rs/libgit-sys/README.md | 15 ++++ contrib/libgit-rs/libgit-sys/build.rs | 35 ++++++++++ .../libgit-sys/public_symbol_export.c | 21 ++++++ .../libgit-sys/public_symbol_export.h | 8 +++ contrib/libgit-rs/libgit-sys/src/lib.rs | 46 +++++++++++++ 9 files changed, 225 insertions(+) create mode 100644 contrib/libgit-rs/libgit-sys/Cargo.lock create mode 100644 contrib/libgit-rs/libgit-sys/Cargo.toml create mode 100644 contrib/libgit-rs/libgit-sys/README.md create mode 100644 contrib/libgit-rs/libgit-sys/build.rs create mode 100644 contrib/libgit-rs/libgit-sys/public_symbol_export.c create mode 100644 contrib/libgit-rs/libgit-sys/public_symbol_export.h create mode 100644 contrib/libgit-rs/libgit-sys/src/lib.rs diff --git a/.gitignore b/.gitignore index 8caf3700c2..dfd72820fb 100644 --- a/.gitignore +++ b/.gitignore @@ -248,3 +248,4 @@ Release/ /git.VC.db *.dSYM /contrib/buildsystems/out +/contrib/libgit-rs/libgit-sys/target diff --git a/Makefile b/Makefile index 7caeb3c872..0090514e55 100644 --- a/Makefile +++ b/Makefile @@ -653,6 +653,8 @@ CURL_CONFIG = curl-config GCOV = gcov STRIP = strip SPATCH = spatch +LD = ld +OBJCOPY = objcopy export TCL_PATH TCLTK_PATH @@ -2713,6 +2715,7 @@ OBJECTS += $(XDIFF_OBJS) OBJECTS += $(FUZZ_OBJS) OBJECTS += $(REFTABLE_OBJS) $(REFTABLE_TEST_OBJS) OBJECTS += $(UNIT_TEST_OBJS) +OBJECTS += contrib/libgit-rs/libgit-sys/public_symbol_export.o ifndef NO_CURL OBJECTS += http.o http-walker.o remote-curl.o @@ -3720,6 +3723,7 @@ clean: profile-clean coverage-clean cocciclean $(RM) $(htmldocs).tar.gz $(manpages).tar.gz $(MAKE) -C Documentation/ clean $(RM) Documentation/GIT-EXCLUDED-PROGRAMS + $(RM) -r contrib/libgit-rs/libgit-sys/target ifndef NO_PERL $(RM) -r perl/build/ endif @@ -3865,3 +3869,12 @@ $(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o \ build-unit-tests: $(UNIT_TEST_PROGS) unit-tests: $(UNIT_TEST_PROGS) t/helper/test-tool$X $(MAKE) -C t/ unit-tests + +contrib/libgit-rs/libgit-sys/partial_symbol_export.o: contrib/libgit-rs/libgit-sys/public_symbol_export.o libgit.a reftable/libreftable.a xdiff/lib.a + $(LD) -r $^ -o $@ + +contrib/libgit-rs/libgit-sys/hidden_symbol_export.o: contrib/libgit-rs/libgit-sys/partial_symbol_export.o + $(OBJCOPY) --localize-hidden $^ $@ + +contrib/libgit-rs/libgit-sys/libgitpub.a: contrib/libgit-rs/libgit-sys/hidden_symbol_export.o + $(AR) $(ARFLAGS) $@ $^ diff --git a/contrib/libgit-rs/libgit-sys/Cargo.lock b/contrib/libgit-rs/libgit-sys/Cargo.lock new file mode 100644 index 0000000000..427a4c66b7 --- /dev/null +++ b/contrib/libgit-rs/libgit-sys/Cargo.lock @@ -0,0 +1,69 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "cc" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libgit-sys" +version = "0.1.0" +dependencies = [ + "autocfg", + "libz-sys", + "make-cmd", +] + +[[package]] +name = "libz-sys" +version = "1.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "make-cmd" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8ca8afbe8af1785e09636acb5a41e08a765f5f0340568716c18a8700ba3c0d3" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" diff --git a/contrib/libgit-rs/libgit-sys/Cargo.toml b/contrib/libgit-rs/libgit-sys/Cargo.toml new file mode 100644 index 0000000000..7a230a4437 --- /dev/null +++ b/contrib/libgit-rs/libgit-sys/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "libgit-sys" +version = "0.1.0" +edition = "2021" +build = "build.rs" +links = "gitpub" +rust-version = "1.63" + +[lib] +path = "src/lib.rs" + +[dependencies] +libz-sys = "1.1.19" + +[build-dependencies] +autocfg = "1.4.0" +make-cmd = "0.1.0" diff --git a/contrib/libgit-rs/libgit-sys/README.md b/contrib/libgit-rs/libgit-sys/README.md new file mode 100644 index 0000000000..7a59602c30 --- /dev/null +++ b/contrib/libgit-rs/libgit-sys/README.md @@ -0,0 +1,15 @@ +# cgit-info + +A small hacky proof-of-concept showing how to provide a Rust FFI for the Git +library. + +## Building + +`cargo build` automatically builds and picks up on changes made to both +the Rust wrapper and git.git code so there is no need to run `make` +beforehand. + +## Running + +Assuming you don't make any changes to the Git source, you can just work from +`contrib/cgit-rs` and use `cargo build` or `cargo run` as usual. diff --git a/contrib/libgit-rs/libgit-sys/build.rs b/contrib/libgit-rs/libgit-sys/build.rs new file mode 100644 index 0000000000..8d74120191 --- /dev/null +++ b/contrib/libgit-rs/libgit-sys/build.rs @@ -0,0 +1,35 @@ +use std::env; +use std::path::PathBuf; + +pub fn main() -> std::io::Result<()> { + let ac = autocfg::new(); + ac.emit_has_path("std::ffi::c_char"); + + let crate_root = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); + let git_root = crate_root.join("../../.."); + let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + + let make_output = make_cmd::gnu_make() + .env("DEVELOPER", "1") + .env_remove("PROFILE") + .current_dir(git_root.clone()) + .args([ + "CFLAGS=-fvisibility=hidden", + "contrib/libgit-rs/libgit-sys/libgitpub.a", + ]) + .output() + .expect("Make failed to run"); + if !make_output.status.success() { + panic!( + "Make failed:\n stdout = {}\n stderr = {}\n", + String::from_utf8(make_output.stdout).unwrap(), + String::from_utf8(make_output.stderr).unwrap() + ); + } + std::fs::copy(crate_root.join("libgitpub.a"), dst.join("libgitpub.a"))?; + println!("cargo:rustc-link-search=native={}", dst.display()); + println!("cargo:rustc-link-lib=gitpub"); + println!("cargo:rerun-if-changed={}", git_root.display()); + + Ok(()) +} diff --git a/contrib/libgit-rs/libgit-sys/public_symbol_export.c b/contrib/libgit-rs/libgit-sys/public_symbol_export.c new file mode 100644 index 0000000000..8e4b94d821 --- /dev/null +++ b/contrib/libgit-rs/libgit-sys/public_symbol_export.c @@ -0,0 +1,21 @@ +// Shim to publicly export Git symbols. These must be renamed so that the +// original symbols can be hidden. Renaming these with a "libgit_" prefix also +// avoids conflicts with other libraries such as libgit2. + +#include "git-compat-util.h" +#include "contrib/libgit-rs/libgit-sys/public_symbol_export.h" +#include "version.h" + +#pragma GCC visibility push(default) + +const char *libgit_user_agent(void) +{ + return git_user_agent(); +} + +const char *libgit_user_agent_sanitized(void) +{ + return git_user_agent_sanitized(); +} + +#pragma GCC visibility pop diff --git a/contrib/libgit-rs/libgit-sys/public_symbol_export.h b/contrib/libgit-rs/libgit-sys/public_symbol_export.h new file mode 100644 index 0000000000..a3372f93fa --- /dev/null +++ b/contrib/libgit-rs/libgit-sys/public_symbol_export.h @@ -0,0 +1,8 @@ +#ifndef PUBLIC_SYMBOL_EXPORT_H +#define PUBLIC_SYMBOL_EXPORT_H + +const char *libgit_user_agent(void); + +const char *libgit_user_agent_sanitized(void); + +#endif /* PUBLIC_SYMBOL_EXPORT_H */ diff --git a/contrib/libgit-rs/libgit-sys/src/lib.rs b/contrib/libgit-rs/libgit-sys/src/lib.rs new file mode 100644 index 0000000000..d4853f3074 --- /dev/null +++ b/contrib/libgit-rs/libgit-sys/src/lib.rs @@ -0,0 +1,46 @@ +#[cfg(has_std__ffi__c_char)] +use std::ffi::c_char; + +#[cfg(not(has_std__ffi__c_char))] +#[allow(non_camel_case_types)] +pub type c_char = i8; + +extern crate libz_sys; + +extern "C" { + pub fn libgit_user_agent() -> *const c_char; + pub fn libgit_user_agent_sanitized() -> *const c_char; +} + +#[cfg(test)] +mod tests { + use std::ffi::CStr; + + use super::*; + + #[test] + fn user_agent_starts_with_git() { + let c_str = unsafe { CStr::from_ptr(libgit_user_agent()) }; + let agent = c_str + .to_str() + .expect("User agent contains invalid UTF-8 data"); + assert!( + agent.starts_with("git/"), + r#"Expected user agent to start with "git/", got: {}"#, + agent + ); + } + + #[test] + fn sanitized_user_agent_starts_with_git() { + let c_str = unsafe { CStr::from_ptr(libgit_user_agent_sanitized()) }; + let agent = c_str + .to_str() + .expect("Sanitized user agent contains invalid UTF-8 data"); + assert!( + agent.starts_with("git/"), + r#"Expected user agent to start with "git/", got: {}"#, + agent + ); + } +} From patchwork Tue Oct 8 23:19:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 13827197 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A7EB218D6D for ; Tue, 8 Oct 2024 23:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429585; cv=none; b=iD7nS24osdRMwScDNEimSOZOX7M6B7WTx2EmDgnNmR9OusDLFTak8UU6pWWE969AYSVEeC6ecW2cgxEYps1t7BkcmalqgD/qtiu94APtpAR03J/cmBRhzmh45jGEqrXt+5lDq0+vrlT2cLi0v725pehj27fg6BV7XMvkm2/AXvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429585; c=relaxed/simple; bh=371viZo39DIJij06+wZWQOheOrWGSz4GDm8hhnCe6Pg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R762H+bDhiOaSDCPsiNi7dOpamKvFbdMZSMBU+lZwgUIwAUdt+U7BFYouOC21YZ2YmZ8NBjv+BWqktpgKDKGYbaIENPrJepoNoTOQ1zGjGqd1qNcKfriQBoqAit6XjQ3UIx9+yuNlO9UaW/C1cqJFetTWGKFtPgua95atT+89nQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FLIDK4Ah; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FLIDK4Ah" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e24a31ad88aso7132054276.1 for ; Tue, 08 Oct 2024 16:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728429583; x=1729034383; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sM0/PbO3TZdZCI1NlRavrtq6Qj6K0lzrH4VoZunlKfQ=; b=FLIDK4AhZAdSAv85PzYCYdQ1+4YCedNKjF2++sXbGy+j7fK6dGp+CxuWlbNIvlnU1n wO+WLzMsDHkcXC3ePQPEqv1XlxZeZOs5J5jEtgELu5JY2qjKUewsN6OlA730zbs0/N4z CG9ex6jCQmZnk8/YO8HgGvuC4LiYYDDLnxUNJ6eoEjhmHu+30BBW2CKsfTcfM9KnUOaW nCbRBj8qegp9CF7SHc9wpCcMF30bH5FzN0WQdPZ3JYJBrEywJdVB3FF1w6WU/sWpuFFc ZlCAls0hTxiA31bcCVNIQaNTHfZLw0X2wTJsgWAxorN3qy/OXERskYZYdOt6ydIUTL+1 oLlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728429583; x=1729034383; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sM0/PbO3TZdZCI1NlRavrtq6Qj6K0lzrH4VoZunlKfQ=; b=UDAYHJsIrTcL4VCIErY8OjKgcyEc07q+imT5LwheY5AGgGtsbw0AO8nIxl6K0fp0ls j4DFddn5NQmR25yGyZU1nGhjqDMwYRlkePZG6qib1yWbEvZC60GAhhdLceXFvyYGFrCQ FDwixvG+y4YHQIcLBSAhtxRaxu83tRdnTiDPu12L1aycwp5CfbG7pg+T2i9W1Mt3T3qw WJHNc9qwKC0ynfnXhMFpJ2jtE/Mb4/WkoJXGX+S/D5vs5X/MhnpWpRfFl8uGR3mr42BE BUTvkjwFvi6RF3nM6nvbKAoqAE614Ilus4W/brqolwXo+6M/kRdKxEMInxdzWJXgIOVO ODQg== X-Gm-Message-State: AOJu0YxGkDmOBmUR6geiTVU6esdR74CqHL+ZdTLD5I1BaLWmLVd5YKwq lttUWpQVmwKuqHj8DyUMBteFUWmN4FSWslZ86tOZGzJxdQ57RcBDle25qUn4QJn7fBqr2hcRja9 bN49G6EsZmj7rTI5mCnFto1n/4cQ+/tSMTfjtS3Xa1uj2omcgCTSOp2Junk7HyV7vCLzjscXZDk et54u1OlEAmISriOQESxh98/wo4pu4ztkPHKsaMZk= X-Google-Smtp-Source: AGHT+IHuaZPSf4xi7hYkSk4hVM0h3mDExmM033KagOWVaRz0pGhiqwwUdYNXhQC1IGyvnGgZueno+8pdTb5/ZQ== X-Received: from lunarfall.svl.corp.google.com ([2620:15c:2d3:204:7c00:8752:4498:cc1b]) (user=steadmon job=sendgmr) by 2002:a25:51c1:0:b0:e28:ee8e:ed9 with SMTP id 3f1490d57ef6-e28fe3205fbmr716276.0.1728429582742; Tue, 08 Oct 2024 16:19:42 -0700 (PDT) Date: Tue, 8 Oct 2024 16:19:33 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <8eeab7b418b99d34a575a293cfac7bdea1e60102.1728429158.git.steadmon@google.com> Subject: [PATCH v4 3/5] libgit-sys: also export some config_set functions From: Josh Steadmon To: git@vger.kernel.org Cc: calvinwan@google.com, spectral@google.com, emilyshaffer@google.com, emrass@google.com, gitster@pobox.com, mh@glandium.org, sandals@crustytoothpaste.net, ps@pks.im, sunshine@sunshineco.com, phillip.wood123@gmail.com, allred.sean@gmail.com In preparation for implementing a higher-level Rust API for accessing Git configs, export some of the upstream configset API via libgitpub and libgit-sys. Since this will be exercised as part of the higher-level API in the next commit, no tests have been added for libgit-sys. While we're at it, add git_configset_alloc() and git_configset_free() functions in libgitpub so that callers can manage config_set structs on the heap. This also allows non-C external consumers to treat config_sets as opaque structs. Co-authored-by: Calvin Wan Signed-off-by: Calvin Wan Signed-off-by: Josh Steadmon --- .../libgit-sys/public_symbol_export.c | 29 +++++++++++++++++ .../libgit-sys/public_symbol_export.h | 10 ++++++ contrib/libgit-rs/libgit-sys/src/lib.rs | 31 ++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/contrib/libgit-rs/libgit-sys/public_symbol_export.c b/contrib/libgit-rs/libgit-sys/public_symbol_export.c index 8e4b94d821..29e8a5363e 100644 --- a/contrib/libgit-rs/libgit-sys/public_symbol_export.c +++ b/contrib/libgit-rs/libgit-sys/public_symbol_export.c @@ -3,11 +3,40 @@ // avoids conflicts with other libraries such as libgit2. #include "git-compat-util.h" +#include "config.h" #include "contrib/libgit-rs/libgit-sys/public_symbol_export.h" #include "version.h" #pragma GCC visibility push(default) +struct libgit_config_set *libgit_configset_alloc(void) +{ + struct config_set *cs = xmalloc(sizeof(struct config_set)); + git_configset_init(cs); + return (struct libgit_config_set *) cs; +} + +void libgit_configset_free(struct libgit_config_set *cs) +{ + git_configset_clear((struct config_set *) cs); + free((struct config_set *) cs); +} + +int libgit_configset_add_file(struct libgit_config_set *cs, const char *filename) +{ + return git_configset_add_file((struct config_set *) cs, filename); +} + +int libgit_configset_get_int(struct libgit_config_set *cs, const char *key, int *dest) +{ + return git_configset_get_int((struct config_set *) cs, key, dest); +} + +int libgit_configset_get_string(struct libgit_config_set *cs, const char *key, char **dest) +{ + return git_configset_get_string((struct config_set *) cs, key, dest); +} + const char *libgit_user_agent(void) { return git_user_agent(); diff --git a/contrib/libgit-rs/libgit-sys/public_symbol_export.h b/contrib/libgit-rs/libgit-sys/public_symbol_export.h index a3372f93fa..701db92d53 100644 --- a/contrib/libgit-rs/libgit-sys/public_symbol_export.h +++ b/contrib/libgit-rs/libgit-sys/public_symbol_export.h @@ -1,6 +1,16 @@ #ifndef PUBLIC_SYMBOL_EXPORT_H #define PUBLIC_SYMBOL_EXPORT_H +struct libgit_config_set *libgit_configset_alloc(void); + +void libgit_configset_free(struct libgit_config_set *cs); + +int libgit_configset_add_file(struct libgit_config_set *cs, const char *filename); + +int libgit_configset_get_int(struct libgit_config_set *cs, const char *key, int *dest); + +int libgit_configset_get_string(struct libgit_config_set *cs, const char *key, char **dest); + const char *libgit_user_agent(void); const char *libgit_user_agent_sanitized(void); diff --git a/contrib/libgit-rs/libgit-sys/src/lib.rs b/contrib/libgit-rs/libgit-sys/src/lib.rs index d4853f3074..dadb4e5f40 100644 --- a/contrib/libgit-rs/libgit-sys/src/lib.rs +++ b/contrib/libgit-rs/libgit-sys/src/lib.rs @@ -1,15 +1,44 @@ #[cfg(has_std__ffi__c_char)] -use std::ffi::c_char; +use std::ffi::{c_char, c_int}; #[cfg(not(has_std__ffi__c_char))] #[allow(non_camel_case_types)] pub type c_char = i8; +#[cfg(not(has_std__ffi__c_char))] +#[allow(non_camel_case_types)] +pub type c_int = i32; + extern crate libz_sys; +#[allow(non_camel_case_types)] +#[repr(C)] +pub struct libgit_config_set { + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} + extern "C" { pub fn libgit_user_agent() -> *const c_char; pub fn libgit_user_agent_sanitized() -> *const c_char; + + pub fn libgit_configset_alloc() -> *mut libgit_config_set; + pub fn libgit_configset_free(cs: *mut libgit_config_set); + + pub fn libgit_configset_add_file(cs: *mut libgit_config_set, filename: *const c_char) -> c_int; + + pub fn libgit_configset_get_int( + cs: *mut libgit_config_set, + key: *const c_char, + int: *mut c_int, + ) -> c_int; + + pub fn libgit_configset_get_string( + cs: *mut libgit_config_set, + key: *const c_char, + dest: *mut *mut c_char, + ) -> c_int; + } #[cfg(test)] From patchwork Tue Oct 8 23:19:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 13827198 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 189E7218D8E for ; Tue, 8 Oct 2024 23:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429589; cv=none; b=um8oMla2JM0RtMT2sGMAyAw3AWwtOZMYncliiCloirgQDOOg07sT59q0jG5tjcaSHbWOpfGxyajEE2tN68XiCdDEKWeuZBoQGMxAvompfeFfALSMfPb/EZx2ThB/boJTsWrZebqJVx16+1lT7GBIftoj2NSWh/T/4M/fa7sYArg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429589; c=relaxed/simple; bh=jcd7xiTm84CXMqpqj19bFFWUqC4qhjdpQJK9IF+6MV0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Sjhd26BsOWJAy20240AqRAkj/Tsw2c9AXjO97fMVRAfzfL9tkAQOsTXRrE32nUi5Y4DlRmmXJULt+ME55AN+8hqeDefO7YiBfdCdXWSnlaHJ1vcafe7an73hRb48ap9G3mCJy4J98znVJlZwwuOtpqc73F9z0H4KOeOXSGHh/Iw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NuYr3V8K; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NuYr3V8K" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e294f38bddso96548537b3.3 for ; Tue, 08 Oct 2024 16:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728429585; x=1729034385; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BAR3tCoa+iaYqvpE61gv8k47B6GsXYN5Tae+Ureei0g=; b=NuYr3V8KfRCj7TkTKbZWM8wHePqb3yTQI4Hz74jxNleJq27wfcKlsx07BGWaD/0A0P kc7cSBwYvRK/x43oVCjTKhWOrr7Bdq1EqQOUX/LP4WofXhFz5skj0NdTogrRg6qBZS3A /B9IJDLdPgOrgyisbYnfATDxWiXL3vzO526mff7sEA6Zj6W3KFcF0bobIGmoKt5Onz4g RyLtBGCpECQPWPWTwQq96boWbsracaG+R7aBOMtHUdmj2IgscsqqhOmudtTQqQ5nfwpT qc+PxYPTIJShx/dsz7ojWMMLjROhpMr3RRWhqLRdBWqxPPu5yWxoeGwBstlGdvnNAaEP D57g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728429585; x=1729034385; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BAR3tCoa+iaYqvpE61gv8k47B6GsXYN5Tae+Ureei0g=; b=dvKvNv5EtLBog8Zte2v/Y4TfqEtlNevggRVu+FUhg3s1skA90jSnHMJ0mFKw86oZKy cwgGERlFmhRCfNK3XKGn1y4m7N7JNXW1TRnNS6eCvMdH1NuNpH3W88+nDhdQgMcxxNKX CzdkzNN1izlSW5M+XnUj4ysP2DHLBHn0IowyVfQNKwxQ6aDaSUp8GnzcyW6qrOJejwKW NMgNib50x1NMyYGXlnhke1KrikykDHMJxsqFlYRCM+5RJ8LoFODnC2jYB9vD5Cn/pvvO OBjZzSv+yGs2/GRF88W2zPvjZxJTPQ+l0V21w+mcNHgaSx3SofxDVibls5q+rzEfE+Rx BFFw== X-Gm-Message-State: AOJu0YzNSARzbx0sn5n+IQPRZ+DZqZtSFhzHJaZZU7QzA53+WdcFuxb3 hg5vUrx3s95DRoFEn7nyF9BdTfNy8W7qFQGt5LUjh0Ux3lbmGNNgXH5YxGqGe4BvWeAztZla6Q2 Pbom0FDtozrqu6Icg0GjkQ0zcaoDZWYfqfpf8/0jiyEQQ67/NlTfPZZiJIs+GbRjknXDh05OYJC QoNAg5KFizz+5Ln/Nj5JBZAc4b6xATClPHNWK0YyE= X-Google-Smtp-Source: AGHT+IGvegBGvAd0HtTTczIhVZJA6Gn+H3M2H3UAvUnvaYsEjjfseFQg90U6ckP+1qxEYoVJ+7zN1dIg+bgB8g== X-Received: from lunarfall.svl.corp.google.com ([2620:15c:2d3:204:7c00:8752:4498:cc1b]) (user=steadmon job=sendgmr) by 2002:a25:d04c:0:b0:e05:6532:166 with SMTP id 3f1490d57ef6-e28fe334f9fmr4007276.1.1728429584750; Tue, 08 Oct 2024 16:19:44 -0700 (PDT) Date: Tue, 8 Oct 2024 16:19:34 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <29599e9c7be1737bcf0de0541c9635212a1b691d.1728429158.git.steadmon@google.com> Subject: [PATCH v4 4/5] libgit: add higher-level libgit crate From: Josh Steadmon To: git@vger.kernel.org Cc: calvinwan@google.com, spectral@google.com, emilyshaffer@google.com, emrass@google.com, gitster@pobox.com, mh@glandium.org, sandals@crustytoothpaste.net, ps@pks.im, sunshine@sunshineco.com, phillip.wood123@gmail.com, allred.sean@gmail.com From: Calvin Wan Wrap `struct config_set` and a few of its associated functions in libgit-sys. Also introduce a higher-level "libgit" crate which provides a more Rust-friendly interface to config_set structs. Co-authored-by: Josh Steadmon Signed-off-by: Calvin Wan Signed-off-by: Josh Steadmon --- .gitignore | 1 + Makefile | 2 +- contrib/libgit-rs/Cargo.lock | 77 ++++++++++++++++++++ contrib/libgit-rs/Cargo.toml | 15 ++++ contrib/libgit-rs/build.rs | 4 ++ contrib/libgit-rs/libgit-sys/src/lib.rs | 4 ++ contrib/libgit-rs/src/lib.rs | 95 +++++++++++++++++++++++++ contrib/libgit-rs/testdata/config1 | 2 + contrib/libgit-rs/testdata/config2 | 2 + contrib/libgit-rs/testdata/config3 | 2 + 10 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 contrib/libgit-rs/Cargo.lock create mode 100644 contrib/libgit-rs/Cargo.toml create mode 100644 contrib/libgit-rs/build.rs create mode 100644 contrib/libgit-rs/src/lib.rs create mode 100644 contrib/libgit-rs/testdata/config1 create mode 100644 contrib/libgit-rs/testdata/config2 create mode 100644 contrib/libgit-rs/testdata/config3 diff --git a/.gitignore b/.gitignore index dfd72820fb..0a42f27117 100644 --- a/.gitignore +++ b/.gitignore @@ -248,4 +248,5 @@ Release/ /git.VC.db *.dSYM /contrib/buildsystems/out +/contrib/libgit-rs/target /contrib/libgit-rs/libgit-sys/target diff --git a/Makefile b/Makefile index 0090514e55..abeee01d9e 100644 --- a/Makefile +++ b/Makefile @@ -3723,7 +3723,7 @@ clean: profile-clean coverage-clean cocciclean $(RM) $(htmldocs).tar.gz $(manpages).tar.gz $(MAKE) -C Documentation/ clean $(RM) Documentation/GIT-EXCLUDED-PROGRAMS - $(RM) -r contrib/libgit-rs/libgit-sys/target + $(RM) -r contrib/libgit-rs/target contrib/libgit-rs/libgit-sys/target ifndef NO_PERL $(RM) -r perl/build/ endif diff --git a/contrib/libgit-rs/Cargo.lock b/contrib/libgit-rs/Cargo.lock new file mode 100644 index 0000000000..a30c7c8d33 --- /dev/null +++ b/contrib/libgit-rs/Cargo.lock @@ -0,0 +1,77 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "cc" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libgit" +version = "0.1.0" +dependencies = [ + "autocfg", + "libgit-sys", +] + +[[package]] +name = "libgit-sys" +version = "0.1.0" +dependencies = [ + "autocfg", + "libz-sys", + "make-cmd", +] + +[[package]] +name = "libz-sys" +version = "1.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "make-cmd" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8ca8afbe8af1785e09636acb5a41e08a765f5f0340568716c18a8700ba3c0d3" + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" diff --git a/contrib/libgit-rs/Cargo.toml b/contrib/libgit-rs/Cargo.toml new file mode 100644 index 0000000000..6b4387b9e7 --- /dev/null +++ b/contrib/libgit-rs/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "libgit" +version = "0.1.0" +edition = "2021" +build = "build.rs" +rust-version = "1.63" + +[lib] +path = "src/lib.rs" + +[dependencies] +libgit-sys = { version = "0.1.0", path = "libgit-sys" } + +[build-dependencies] +autocfg = "1.4.0" diff --git a/contrib/libgit-rs/build.rs b/contrib/libgit-rs/build.rs new file mode 100644 index 0000000000..f8bd01a690 --- /dev/null +++ b/contrib/libgit-rs/build.rs @@ -0,0 +1,4 @@ +pub fn main() { + let ac = autocfg::new(); + ac.emit_has_path("std::ffi::c_char"); +} diff --git a/contrib/libgit-rs/libgit-sys/src/lib.rs b/contrib/libgit-rs/libgit-sys/src/lib.rs index dadb4e5f40..4bfc650450 100644 --- a/contrib/libgit-rs/libgit-sys/src/lib.rs +++ b/contrib/libgit-rs/libgit-sys/src/lib.rs @@ -1,3 +1,5 @@ +use std::ffi::c_void; + #[cfg(has_std__ffi__c_char)] use std::ffi::{c_char, c_int}; @@ -19,6 +21,8 @@ pub struct libgit_config_set { } extern "C" { + pub fn free(ptr: *mut c_void); + pub fn libgit_user_agent() -> *const c_char; pub fn libgit_user_agent_sanitized() -> *const c_char; diff --git a/contrib/libgit-rs/src/lib.rs b/contrib/libgit-rs/src/lib.rs new file mode 100644 index 0000000000..d228091f3d --- /dev/null +++ b/contrib/libgit-rs/src/lib.rs @@ -0,0 +1,95 @@ +use std::ffi::{c_void, CStr, CString}; +use std::path::Path; + +#[cfg(has_std__ffi__c_char)] +use std::ffi::{c_char, c_int}; + +#[cfg(not(has_std__ffi__c_char))] +#[allow(non_camel_case_types)] +pub type c_char = i8; + +#[cfg(not(has_std__ffi__c_char))] +#[allow(non_camel_case_types)] +pub type c_int = i32; + +use libgit_sys::*; + +pub struct ConfigSet(*mut libgit_config_set); +impl ConfigSet { + pub fn new() -> Self { + unsafe { ConfigSet(libgit_configset_alloc()) } + } + + pub fn add_files(&mut self, files: &[&Path]) { + for file in files { + let pstr = file.to_str().expect("Invalid UTF-8"); + let rs = CString::new(pstr).expect("Couldn't convert to CString"); + unsafe { + libgit_configset_add_file(self.0, rs.as_ptr()); + } + } + } + + pub fn get_int(&mut self, key: &str) -> Option { + let key = CString::new(key).expect("Couldn't convert to CString"); + let mut val: c_int = 0; + unsafe { + if libgit_configset_get_int(self.0, key.as_ptr(), &mut val as *mut c_int) != 0 { + return None; + } + } + + Some(val) + } + + pub fn get_string(&mut self, key: &str) -> Option { + let key = CString::new(key).expect("Couldn't convert key to CString"); + let mut val: *mut c_char = std::ptr::null_mut(); + unsafe { + if libgit_configset_get_string(self.0, key.as_ptr(), &mut val as *mut *mut c_char) != 0 + { + return None; + } + let borrowed_str = CStr::from_ptr(val); + let owned_str = + String::from(borrowed_str.to_str().expect("Couldn't convert val to str")); + free(val as *mut c_void); // Free the xstrdup()ed pointer from the C side + Some(owned_str) + } + } +} + +impl Default for ConfigSet { + fn default() -> Self { + Self::new() + } +} + +impl Drop for ConfigSet { + fn drop(&mut self) { + unsafe { + libgit_configset_free(self.0); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn load_configs_via_configset() { + let mut cs = ConfigSet::new(); + cs.add_files(&[ + Path::new("testdata/config1"), + Path::new("testdata/config2"), + Path::new("testdata/config3"), + ]); + // ConfigSet retrieves correct value + assert_eq!(cs.get_int("trace2.eventTarget"), Some(1)); + // ConfigSet respects last config value set + assert_eq!(cs.get_int("trace2.eventNesting"), Some(3)); + // ConfigSet returns None for missing key + assert_eq!(cs.get_string("foo.bar"), None); + } +} diff --git a/contrib/libgit-rs/testdata/config1 b/contrib/libgit-rs/testdata/config1 new file mode 100644 index 0000000000..4e9a9d25d1 --- /dev/null +++ b/contrib/libgit-rs/testdata/config1 @@ -0,0 +1,2 @@ +[trace2] + eventNesting = 1 diff --git a/contrib/libgit-rs/testdata/config2 b/contrib/libgit-rs/testdata/config2 new file mode 100644 index 0000000000..b8d1eca423 --- /dev/null +++ b/contrib/libgit-rs/testdata/config2 @@ -0,0 +1,2 @@ +[trace2] + eventTarget = 1 diff --git a/contrib/libgit-rs/testdata/config3 b/contrib/libgit-rs/testdata/config3 new file mode 100644 index 0000000000..ca7b9a7c38 --- /dev/null +++ b/contrib/libgit-rs/testdata/config3 @@ -0,0 +1,2 @@ +[trace2] + eventNesting = 3 From patchwork Tue Oct 8 23:19:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 13827199 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D18A218D95 for ; Tue, 8 Oct 2024 23:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429589; cv=none; b=NeAXgUQK/gxi3BU/YtK1pVbZtSdGnCP+czyqBmHarvhipsHN8WCgMN6WnyJNOfBk64n5cBT0NC158bWeppSS+8Gss/ke5hVAG6lcwcBFZc2sc9iPmcVP5m3VWK9Krr8PDfXWXqUn6z1UPgdYMQZFjOEBKXUIS3Rw6xWiFkCHVlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728429589; c=relaxed/simple; bh=TuAq78OU6knsjT9nouY+PkCmkDf1IBft+fG8fL0vai4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eeFCJs4Eqmnv7x3l/XqnxUvSXXg+gICZuOCnqrmlfQBDxX/gK2p7kg59oQ6CcF8xC5vp7Jy/1GxCzTHfTJeM7Bg8l1Jzku8QSKZ8lpbFVnt3EpvDzb+wZ2AxMDr3nlk3zA68LgLebRbPVGJza0c/mFSn9ZH5bwXUsGk5ywhh9u0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=y5egI39G; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="y5egI39G" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e249fafe1ebso10362762276.2 for ; Tue, 08 Oct 2024 16:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728429587; x=1729034387; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ojv9PmORtHTTAj+ZcCauWaRxsQ7gqK5X5FpuMDe3UEM=; b=y5egI39GCt42GgFGij4rJGKv+gxtjg4CiVvbK9YSFu127w86s3FjxiGKqU/EIuRlwN YyshMlybWMJq40QdkLnfaCUgwQgPTqUmyOOTBhWAP0oqPXw86BLH34G3FcefzzMXn3jp mMSN4e/WGlhYWkTfXQUw4luijOr2aB0CJSGfOrMjTTIe0FEqFaGNvQhrXLi0fyOiAARo kBaUndnPsLRWKpNKYOU2K69RN2Oa9tZwj+6M5z2xihk29VJthn1udqesg9ejf6kfPjzA TShTtw2nFM3IQWl6px1wRSy/yduclCZ9HtUKfuQgM4mKnX2jaP92fW5Cfd2IwFHpb2k1 y2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728429587; x=1729034387; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ojv9PmORtHTTAj+ZcCauWaRxsQ7gqK5X5FpuMDe3UEM=; b=HM5yd/abK5rj3mRRKgcylzzxSkCTBq4tB0AmNP+it6IXNGdEaJBNRaeV/VJ15XL3HD Y4GdkZlY76aaYW7Xs1qf06+bE31NPjh+91piwF3m/8w8Qhz1PdXxu/P+GYy1S8GdEhyf TgnoBpiMsXIVJVunViND/Iobm8yz2UN9TJAv9cyPThrqwoSuEDIUkmWZxmeeLsAUBE4S DbQVDSHPohTiwAF6qy4uONfFdVdK4vOENa/1z3WrzLv5wtrBFxFBCD88jDSNjMXm5oah nbb7LLGsy0XZK4Eus7/QO4sejLh4AWHEuiZ148ndImT7ukRWJL/9uEn+Xi6sS9BqAFci FeQA== X-Gm-Message-State: AOJu0YxhUQfjCNPqUl9uESszgMaJkAuRxqWX9QIgEeTR1i/QuzWD2kQO k1GOX4QpslKdewRgEfxCyE5LfOrG0u7yWq6I68y+r1R9GXyvRKydaZ7f98abNEmWPqxqKqXSN/+ bgdadymDV9ZvHy5z+nUostYBYoGRQ4WB1bKldLeue1QLMg6q1zHxSrL6CHrKumkHCeczHE51eEv vYcBUO8QWpJ7lCNLLN7n3+kz6xNVCaUrjrTyvcg1I= X-Google-Smtp-Source: AGHT+IEVA4UXeZZJaTsXr6naRASbYs2amOPf68GGFOd3kg8EJudxnRwCF2CyC8MF0kPXQWFEP9/YLyBd4mlWsQ== X-Received: from lunarfall.svl.corp.google.com ([2620:15c:2d3:204:7c00:8752:4498:cc1b]) (user=steadmon job=sendgmr) by 2002:a25:df41:0:b0:e28:8f62:e735 with SMTP id 3f1490d57ef6-e28fe44658emr422276.1.1728429586839; Tue, 08 Oct 2024 16:19:46 -0700 (PDT) Date: Tue, 8 Oct 2024 16:19:35 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <2ed503216f8e14d7b516c488caf3c76ffcb15697.1728429158.git.steadmon@google.com> Subject: [PATCH v4 5/5] Makefile: add option to build and test libgit-rs and libgit-rs-sys From: Josh Steadmon To: git@vger.kernel.org Cc: calvinwan@google.com, spectral@google.com, emilyshaffer@google.com, emrass@google.com, gitster@pobox.com, mh@glandium.org, sandals@crustytoothpaste.net, ps@pks.im, sunshine@sunshineco.com, phillip.wood123@gmail.com, allred.sean@gmail.com From: Calvin Wan Add libgitrs, libgitrs-sys, libgitrs-test, and libgitrs-sys-test targets to their respective Makefiles so they can be built and tested without having to run cargo build/test. Add environment variable, INCLUDE_LIBGIT_RS, that when set, automatically builds and tests libgit-rs and libgit-rs-sys when `make all` is ran. Signed-off-by: Calvin Wan Signed-off-by: Josh Steadmon --- Makefile | 16 ++++++++++++++++ t/Makefile | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Makefile b/Makefile index abeee01d9e..41ad458aef 100644 --- a/Makefile +++ b/Makefile @@ -3870,6 +3870,22 @@ build-unit-tests: $(UNIT_TEST_PROGS) unit-tests: $(UNIT_TEST_PROGS) t/helper/test-tool$X $(MAKE) -C t/ unit-tests +.PHONY: libgitrs-sys +libgitrs-sys: + $(QUIET)(\ + cd contrib/libgit-rs/libgit-sys && \ + cargo build \ + ) +.PHONY: libgitrs +libgitrs: + $(QUIET)(\ + cd contrib/libgit-rs && \ + cargo build \ + ) +ifdef INCLUDE_LIBGIT_RS +all:: libgitrs +endif + contrib/libgit-rs/libgit-sys/partial_symbol_export.o: contrib/libgit-rs/libgit-sys/public_symbol_export.o libgit.a reftable/libreftable.a xdiff/lib.a $(LD) -r $^ -o $@ diff --git a/t/Makefile b/t/Makefile index b2eb9f770b..066cb5c2b4 100644 --- a/t/Makefile +++ b/t/Makefile @@ -169,3 +169,19 @@ perf: .PHONY: pre-clean $(T) aggregate-results clean valgrind perf \ check-chainlint clean-chainlint test-chainlint $(UNIT_TESTS) + +.PHONY: libgitrs-sys-test +libgitrs-sys-test: + $(QUIET)(\ + cd ../contrib/libgit-rs/libgit-sys && \ + cargo test \ + ) +.PHONY: libgitrs-test +libgitrs-test: + $(QUIET)(\ + cd ../contrib/libgit-rs && \ + cargo test \ + ) +ifdef INCLUDE_LIBGIT_RS +all:: libgitrs-sys-test libgitrs-test +endif