Skip to content

Commit

Permalink
Fix #49 error of caused by Windows GCC compiler (#50)
Browse files Browse the repository at this point in the history
* Remove igraph dependency

* Fix windows installation of Rust library

* Remove unicode symbols not compatible with LaTeX

* remove vendor folder

* force linker for windows to be rust-lld

* improved rust arch detection

* remove forced linker

* revert change of rust arch detection script

* revert change of rust arch detection script

* add empty libgcc_eh.a

* fix(win): fix libgcc_mock folder not being created

* remove documentation page
  • Loading branch information
iblacksand authored Aug 1, 2024
1 parent e2bba4c commit cec3285
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 103 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Depends: R (>= 4.0)
Imports: methods, dplyr, doRNG, readr, parallel (>= 3.3.2),
doParallel (>= 1.0.10), foreach (>= 1.4.0),
jsonlite, httr, rlang, svglite,
igraph, whisker, apcluster, Rcpp, cluster, poolr
whisker, apcluster, Rcpp, cluster, poolr
NeedsCompilation: yes
LinkingTo: Rcpp
RoxygenNote: 7.3.1
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ importFrom(httr,GET)
importFrom(httr,POST)
importFrom(httr,content)
importFrom(httr,modify_url)
importFrom(igraph,V)
importFrom(igraph,get.adjacency)
importFrom(igraph,graph.edgelist)
importFrom(jsonlite,fromJSON)
importFrom(jsonlite,toJSON)
importFrom(parallel,makeCluster)
Expand Down
14 changes: 7 additions & 7 deletions R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ NULL
#'
#' ## Diagram
#' ```shell
#' Gene Sets
#' ┌───────────┐ First column named 'gene' containing gene name
#' A0100110100 1 = in set
#' Genes B0100101000 0 = not in set
#' C1011101001 Due to limitiations with extendr-api v 0.6.0,
#' └───────────┘ function returns a list, and the R package will
#' add the first 'gene' column
#' Gene Sets
#' First column named 'gene' containing gene name
#' A0100110100 1 = in set
#' Genes B0100101000 0 = not in set
#' C1011101001 Due to limitiations with extendr-api v 0.6.0,
#' function returns a list, and the R package will
#' add the first 'gene' column
#' ```
#' @param gmt A Data Frame with geneSet and gene columns from the GMT file
#' @param genes A vector of genes
Expand Down
27 changes: 0 additions & 27 deletions R/randomWalkEnrichment.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#' @importFrom httr content modify_url
#' @importFrom readr read_tsv
#' @importFrom dplyr filter arrange %>% desc
#' @importFrom igraph graph.edgelist V
randomWalkEnrichment <- function(organism, network, method, inputSeed, topRank, highlightSeedNum, sigMethod, fdrThr, topThr, projectDir, projectName, cache, hostName) {
fileName <- paste(projectName, network, method, sep = ".")
if (startsWith(hostName, "file://")) {
Expand All @@ -20,8 +19,6 @@ randomWalkEnrichment <- function(organism, network, method, inputSeed, topRank,
gmtUrl <- modify_url(geneSetUrl, query = list(organism = organism, database = "geneontology_Biological_Process", standardId = "genesymbol", fileType = "gmt"))
goAnn <- readGmt(gmtUrl, cache = cache)
}
# netGraph <- graph.edgelist(net, directed=FALSE)
# netNode <- V(netGraph)$name
unique_nodes <- unlist(unique(c(net[, 1], net[, 2])))


Expand All @@ -44,10 +41,7 @@ randomWalkEnrichment <- function(organism, network, method, inputSeed, topRank,
for (i in 1:nrow(net)) {
organize_net[[i]] <- c(net[i, 1], net[i, 2])
}
# pt1 <- .netwalker(seeds, netGraph, r=0.5)
# print(head(seeds))
random_walk_res <- nta_rust(organize_net, seeds)
# print(head(random_walk_res))
gS <- data.frame(name = random_walk_res$nodes, score = random_walk_res$scores, per = 1, stringsAsFactors = F)

if (method == "Network_Expansion") {
Expand Down Expand Up @@ -110,27 +104,6 @@ randomWalkEnrichment <- function(organism, network, method, inputSeed, topRank,
return(termInfo)
}

#' @importFrom igraph get.adjacency
.netwalker <- function(seed, network, r = 0.5) {
adjMatrix <- get.adjacency(network, sparse = FALSE)
de <- apply(adjMatrix, 2, sum)
w <- t(t(adjMatrix) / de)

p0 <- array(0, dim = c(nrow(w), 1))
rownames(p0) <- rownames(w)
p0[seed, 1] <- 1 / length(seed)

pt <- p0
pt1 <- (1 - r) * (w %*% pt) + r * p0

while (sum(abs(pt1 - pt)) > 1e-6) {
pt <- pt1
pt1 <- (1 - r) * (w %*% pt) + r * p0
}

return(pt1)
}

#' @importFrom dplyr select filter arrange left_join mutate %>%
#' @importFrom httr POST content
#' @importFrom readr read_tsv
Expand Down
14 changes: 7 additions & 7 deletions man/fill_input_data_frame.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 13 additions & 50 deletions src/Makevars.win.in
Original file line number Diff line number Diff line change
@@ -1,60 +1,23 @@
TARGET = $(subst 64,x86_64,$(subst 32,i686,$(WIN)))-pc-windows-gnu

TARGET = x86_64-pc-windows-gnu

# Rtools42 doesn't have the linker in the location that cargo expects, so we
# need to overwrite it via configuration.
CARGO_LINKER = x86_64-w64-mingw32.static.posix-gcc.exe

VENDORING = @VENDORING@
OFFLINE_OPTION = @OFFLINE_OPTION@


TARGET = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript.exe" "../tools/rustarch.R")
LIBDIR = rust/target/$(TARGET)/release
STATLIB = $(LIBDIR)/WebGestaltR.a
PKG_LIBS = -L$(LIBDIR) -lWebGestaltR -lws2_32 -ladvapi32 -lgdi32 -lbcrypt -lcrypt32 -luserenv -lntdll
TARGET_DIR = rust/target
LIBDIR = $(TARGET_DIR)/$(TARGET)/release
STATLIB = $(LIBDIR)/libWebGestaltR.a
PKG_LIBS = -L$(LIBDIR) -lWebGestaltR -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll

all: C_clean
all: clean rustup

$(SHLIB): $(STATLIB)

CARGOTMP = $(CURDIR)/.cargo

$(STATLIB):
if [ -f rust/vendor.tar.xz ]; then tar xf rust/vendor.tar.xz && mkdir -p .cargo && cp windows-config.toml .cargo/config.toml; fi
mkdir -p $(TARGET_DIR)/libgcc_mock
# `rustc` adds `-lgcc_eh` flags to the compiler, but Rtools' GCC doesn't have
# `libgcc_eh` due to the compilation settings. So, in order to please the
# compiler, we need to add empty `libgcc_eh` to the library search paths.
#
# For more details, please refer to
# https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a
mkdir -p $(LIBDIR)/libgcc_mock && touch $(LIBDIR)/libgcc_mock/libgcc_eh.a

# CARGO_LINKER is provided in Makevars.ucrt for R >= 4.2
# vendoring (Note: to avoid NOTE of "Found the following hidden files and
# directories", .cargo needs to be created here)
if [ "$(VENDORING)" = "yes" ]; then \
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust && \
mkdir -p ./.cargo && \
cp ./config.toml ./.cargo/config.toml; \
fi

if [ "$(NOT_CRAN)" != "true" ]; then \
export CARGO_HOME=$(CARGOTMP); \
fi && \
@BEFORE_CARGO_BUILD@ export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="$(CARGO_LINKER)" && \
export LIBRARY_PATH="$${LIBRARY_PATH};$(CURDIR)/$(TARGET_DIR)/libgcc_mock" && \
cargo build --target=$(TARGET) --jobs 2 --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) $(OFFLINE_OPTION)
if [ "$(NOT_CRAN)" != "true" ]; then \
rm -Rf $(CARGOTMP) && \
rm -Rf $(LIBDIR)/build; \
fi
@AFTER_CARGO_BUILD@

C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
export LIBRARY_PATH="$${LIBRARY_PATH};$(CURDIR)/$(TARGET_DIR)/libgcc_mock"
PATH="$(USERPROFILE)\.cargo\bin:$(PATH)" cargo build --target=$(TARGET) --release --manifest-path=rust/Cargo.toml

clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR)
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) rust/target
rm -Rf vendor

rustup:
rustup target add $(TARGET) || true
2 changes: 1 addition & 1 deletion src/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ branch = "master"
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "rust/vendor"
directory = "rust/vendor"
14 changes: 7 additions & 7 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use webgestalt_lib::{
///
/// ## Diagram
/// ```shell
/// Gene Sets
/// ┌───────────┐ First column named 'gene' containing gene name
/// A0100110100 1 = in set
/// Genes B0100101000 0 = not in set
/// C1011101001 Due to limitiations with extendr-api v 0.6.0,
/// └───────────┘ function returns a list, and the R package will
/// add the first 'gene' column
/// Gene Sets
/// First column named 'gene' containing gene name
/// A0100110100 1 = in set
/// Genes B0100101000 0 = not in set
/// C1011101001 Due to limitiations with extendr-api v 0.6.0,
/// function returns a list, and the R package will
/// add the first 'gene' column
/// ```
/// @param gmt A Data Frame with geneSet and gene columns from the GMT file
/// @param genes A vector of genes
Expand Down
13 changes: 13 additions & 0 deletions src/windows-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[net]
git-fetch-with-cli = true

[source.crates-io]
replace-with = "vendored-sources"

[source."git+https://github.com/bzhanglab/webgestalt_rust.git?branch=master"]
git = "https://github.com/bzhanglab/webgestalt_rust.git"
branch = "master"
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"
12 changes: 12 additions & 0 deletions tools/rustarch.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See notes in FAQ about ARM64 support:
# https://github.com/r-rust/faq#does-rust-support-windows-on-arm64-aarch64
arch <- if (grepl("aarch", R.version$platform)) {
"aarch64-pc-windows-gnullvm"
} else if (grepl("clang", Sys.getenv("R_COMPILED_BY"))) {
"x86_64-pc-windows-gnullvm"
} else if (grepl("i386", R.version$platform)) {
"i686-pc-windows-gnu"
} else {
"x86_64-pc-windows-gnu"
}
cat(arch)

0 comments on commit cec3285

Please sign in to comment.