Why rustc did not include libmariadb into release binary? - mysql

I thought rust compiler uses static binding and includes all the dependent libraries at compile time (hence executable size).
But when I've tried to use compiled binary in a docker scratch image with actix, mysql client and diesel with mysql feature enabled this error pops up:
error while loading shared libraries: libmariadb.so.3: cannot open shared object file: No such file or director
My dockerfile:
FROM rust:1.43 as builder
WORKDIR /var/app
RUN apt-get update && apt-get install -y libclang-dev clang libmariadb-dev-compat libmariadb-dev
COPY Cargo.toml Cargo.lock diesel.toml ./
COPY src src
RUN cargo install diesel_cli --no-default-features --features mysql
RUN cp /usr/local/cargo/bin/diesel diesel
RUN cargo build --release
FROM ubuntu
USER 1000
WORKDIR /var/app
COPY --from=builder --chown=1000:1000 /var/app/target/release/sniper_api app
COPY --from=builder --chown=1000:1000 /var/app/diesel diesel
CMD ["./app"]
My cargo:
[dependencies]
actix-rt = "1.0.0"
actix-web = "2.0.0"
actix-http = "1.0.1"
serde = { version = "1.0.112", features=["derive"] }
dotenv = "0.15.0"
config = "0.10.1"
diesel = { version = "1.4.2", features = ["mysql","r2d2"]}
futures = "0.3.5"
r2d2 = "0.8.8"
r2d2_mysql = "18.0.0"
env_logger = "0.7.1"
But if I use ubuntu/debian/etc. image as runtime and install libmariadb-dev-compat libmariadb-dev everything is fine. Is there a way to get true single binary with mysql connector in Rust?

I thought rust compiler uses static binding and includes all the dependent libraries at compile time (hence executable size).
This only applies for Rust libraries. For other languages, there is generally little rustc can do.
In particular in this case, diesel provides mysql/mariadb support via the mysqlclient-sys crate for which there currently is an issue and an accompanying PR open to support static linking for this library. But they haven't been merged yet.

Related

Can not deploy Go in Oracle Cloud Function using Cloud Shell

I tried to Creating and Deploying Oracle Cloud Functions by following the official documentation instructions. I can create and deploy using java runtime but when I deploy go runtime always return error.
I tried to init Go function using this command in Oracle Cloud Shell:
fn init --runtime go hello-go
then I tried to deploy it
fn -v deploy --app test
but it returned error like below:
Deploying hello-go to app: test
Bumped to version 0.0.7
Building image bom.ocir.io/bmptwl2psusa/repo/hello-go:0.0.7
FN_REGISTRY: bom.ocir.io/bmptwl2psusa/repo
Current Context: ap-mumbai-1
Sending build context to Docker daemon 5.632kB
Step 1/10 : FROM fnproject/go:dev as build-stage
---> 96c8fb94a8e1
Step 2/10 : WORKDIR /function
---> Using cache
---> 8961dd299ec1
Step 3/10 : WORKDIR /go/src/func/
---> Using cache
---> 5a4c2c6e13f1
Step 4/10 : ENV GO111MODULE=on
---> Using cache
---> 22022ff2fcf8
Step 5/10 : COPY . .
---> 714622a6ff03
Step 6/10 : RUN cd /go/src/func/ && go build -o func
---> Running in 39fedbc476f4
build func: cannot find module for path github.com/fnproject/fdk-go
The command '/bin/sh -c cd /go/src/func/ && go build -o func' returned a non-zero code: 1
Fn: error running docker build: exit status 1
When I'm using java runtime with fn init --runtime java hello-java command, it's successfully deployed, Why always fail when using go?
I tried to run go build -o func in hello-go directory but it's returned:
go: finding module for package github.com/fnproject/fdk-go
go: writing stat cache: mkdir /usr/share/gocode/pkg: permission denied
go: downloading github.com/fnproject/fdk-go v0.0.3
func.go:10:2: mkdir /usr/share/gocode/pkg: permission denied
I know it happened because /usr/share/gocode/ directory is under root user, but I dont know how to change the permission on that folder because Oracle Cloud Shell can not use root user or sudo. (based on this answer)
Maybe I can do it if I use real VM shell or local shell/terminal, but I want to use Oracle Cloud Shell because I just followed official instructions that suggested me using Oracle Cloud Shell, so how to deploy Oracle Cloud Functions with Go runtime using Oracle Cloud Shell?
Mostly the official documentations only give the examples using Java runtime, that make me paranoid when using go.
This is a bug in cloudshell that we are figuring out the best way to solve.
As a short-term workaround you can do this once:
mkdir ${HOME}/gopath
Then set this in your terminal:
export GOPATH=${HOME}/gopath
You should probably edit your ~/.bashrc to set the GOPATH variable automatically so you don't forget

Run gulp via cake Start-Process

I'm building site via gulp inside a windows container:
mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-1909
The container have nodejs and gulp-cli installed in it as following (in Dockerfile):
#Install NodeJs
RUN (New-Object Net.WebClient).DownloadFile('https://nodejs.org/dist/v12.16.3/node-v12.16.3-win-x64.zip', 'node.zip'); \
Expand-Archive -LiteralPath 'node.zip' -DestinationPath '.' ; \
Start-Process -FilePath '.\node-v12.16.3-win-x64\npm' -NoNewWindow -Wait -ArgumentList 'install -g gulp-cli' ; \
$env:PATH = 'c:\tools\node-v12.16.3-win-x64;' + $env:PATH; \
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);
As you can see I'm installing node in the container under c:\tools\node-v12.16.3-win-x64.
In my cake script i try to execute gulp file as following:
StartProcess("cmd", new ProcessSettings {
Arguments = "/c gulp",
WorkingDirectory = projectDir)
});
But seems that Start-Process cannot find the file... I'm getting this output from cake Start-Process:
Executing: "cmd" /c gulp
'gulp' is not recognized as an internal or external command
Running the container interactive I can see the file it is in that place and if I run gulp from projectDir all works.
I've also try it to run it like all of the following forms without success:
StartProcess("powershell", new ProcessSettings {
Arguments = "gulp",
WorkingDirectory = projectDir)
});
StartProcess("gulp");
StartProcess("gulp.cmd");
This is the output from within the container regarding npn, gulp versions (requested from comments):
EDIT:
That 'Local version: Unknown' seems off. Is C:\code your project directory?
When I look at the 'official' gulp configuration steps, the installation results in having both a CLI and local version.
(see: https://gulpjs.com/docs/en/getting-started/quick-start/ )
You could consider using Cake.Gulp which can help run gulp with cake either from a local or global installation:
Namespace: https://cakebuild.net/api/Cake.Gulp/
Example usage: https://cake-contrib.github.io/Cake.Gulp/docs/usage/examples
Perhaps making sure that npm installed gulp locally might do the trick because cake is expecting a local variant. I am unfortunately inexperienced with cake, so this is my best guess after doing some basic research.
(one of my sources: Why do we need to install gulp globally and locally? )
Original answer
You could try using an absolute path to the gulp application.
For example:
StartProcess("cmd", new ProcessSettings {
Arguments = "/c c:\tools\node-v12.16.3-win-x64\gulp",
WorkingDirectory = projectDir)
});
It could be that your environment is not set properly, I found this that could be of use: Appending to PATH in a Windows Docker container

Can a jlinked runtime be deployed with javapackager?

The instructions to javapackager just above Example 2-1 in the Java SE Deployment Guide/Self-Contained Application Packaging state that a jar file is required in the -deploy command.
If I use a modular jar, I get this error message:
Exception: java.lang.Exception: Error: Modules are not allowed in srcfiles: [dist\tcdmod.jar].
If I use the equivalent non-modular jar, the resulting package includes the complete runtime. But I want to use the reduced runtime I made with jlink that is in the /dist folder.
Can the javapackager command deploy with a jlink-generated runtime?
How?
The section titled "Customization of the JRE" makes no mention of the javapackager command.
The following section "Packaging for Modular Applications" has a following line:
Use the Java Packager tool to package modular applications as well as non-modular applications.
Is the Java Packager tool distinct from javapackager? There are no examples using javapackager in this section.
Here is the javapacker command that I used:
javapackager -deploy -native -outdir packages -outfile ToneCircleDrone -srcdir dist -srcfiles tcdplain.jar -appclass com.adonax.tanpura.TCDLaunch -name "ToneCircleDrone" -title "ToneCircleDrone test"
The instructions in the javapackager documentation make no mention of the scenario where a jlink runtime is used. There is a Bundler argument -Bruntime but it is only used to point to an installed runtime other than the system default, AFAIK.
The javapackager provided with JDK 9 and up uses jlink to generate the jre image:
For self-contained applications, the Java Packager for JDK 9 packages
applications with a JDK 9 runtime image generated by the jlink tool. To
package a JDK 8 or JDK 7 JRE with your application, use the JDK 8 Java
Packager.
https://docs.oracle.com/javase/9/tools/javapackager.htm#JSWOR719
You can even pass arguments to jlink using -BjlinkOptions=<options>
Additionally, -Bruntime is only valid for packages deployed using -deploy -native jnlp
For compiling a modular application, instead of -srcdir, use --module-path <dir>, and then specify the main module using -m <module name>.
EDIT: While there is no documentation on -BjlinkOptions, it is present in the javapackager source
jdk.packager/jdk.packager.internal.legacy.JLinkBundlerHelper
https://github.com/teamfx/openjfx-10-dev-rt/blob/bf971fe212e9bd14b164e4c1058bc307734e11b1/modules/jdk.packager/src/main/java/jdk/packager/internal/legacy/JLinkBundlerHelper.java#L96
Example Usage: -BjlinkOptions=compress=2 will make javapackager run jlink with the --compress=2 flag, generating the JRE image with Zip Level compression.
Aditionally, running javapackager with the flag -Bverbose=true will show you exactly which arguments are being passed to jlink with a line in the output something like this:
userArguments = {strip-debug=1 compress=2}

Why rasqal configuration can't recognize the already raptor library on cygwin?

I am trying to install rasqal 0.9.20 library http://librdf.org/rasqal/ onto a windows 7 machine with cygwin.Earlier i have successfully installed the raptor-2.2.0 library http://librdf.org/raptor/ and i can verify this with the rapper tool was created after the installation(./configure , ./make ,/make install)
The error that i am getting from the configuration of rasqal is :
./configure --enable-raptor2
...
checking for raptor... configure: error: Raptor2 is not installed - see http://librdf.org/raptor/ to get a version newer than 1.9.0
I can't find a way to fix it. The code from the cofigure file that handles this flag is the below :
11840 # raptor is REQUIRED despite the checking here
11841 RAPTOR_MIN_VERSION=1.4.19
11842 RAPTOR_MAX_VERSION=1.8.99
11843 RAPTOR2_MIN_VERSION=1.9.0
11844
11845 raptor2=no
11846 # Check whether --enable-raptor2 was given.
11847 if test "${enable_raptor2+set}" = set; then :
11848 enableval=$enable_raptor2; raptor2="$enableval"
11849 else
11850 raptor2="no"
11851 fi
Raptor 2.0.0 uses only pkg-config to provide configuration information, raptor-config was removed. The same applies to rasqal itself, the rasqal-config program will go away at some point. The --enable-raptor2 option to rasqal and librdf was for testing the beta raptor2, and it has been removed from rasqal 0.9.22 and librdf GIT head.
Set PKG_CONFIG_PATH to include the correct path:
env PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure
Another method, if available on your system, is to define the environment variable in /etc/environment:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

mysql qt in linux and windows

On a centos,
qt creator 1.2.1
qtsdk-2009.04
what step by step is needed to create mysql driver, in linux and in windows.
such that running following command gives an positive output
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("xxxxxxxxxx");
db.setDatabaseName("xxxxxxxdb");
db.setUserName("xxxxxxxxxxx");
db.setPassword("xxxxxxxxxxx");
bool ok = db.open();
Brgds,
kNish
I used to have PostgreSQL(8.3) driver compiled successfully.Following is the batch cmds to do the job(replace the path with yours).
cd D:\SoftwareSetup\Dev\Qt\2009.05\qt\src\plugins\sqldrivers\psql
D:\SoftwareSetup\Dev\Qt\2009.05\qt\bin\qmake “INCLUDEPATH+=D:\SoftwareSetup\Dev\PostgreSQL\8.3\include” “LIBS+=D:\SoftwareSetup\Dev\PostgreSQL\8.3\lib\libpq.lib” psql.pro
#”D:\SoftwareSetup\Dev\Microsoft Visual Studio 9.0\VC\bin\nmake”
“D:\SoftwareSetup\Dev\Qt\2009.05\mingw\bin\mingw32-make”
pause
If you use VC compiler,use nmake to get it compiled,
and I also referenced to following two links to find out library dependency:
http://lists.trolltech.com/qt-interest/2006-11/thread00265-0.html
http://doc.trolltech.com/4.6/sql-driver.html#how-to-build-the-qdts-plugin-on-windows
This page from Nokia Qt doc may be helpful on *nix(and Windows):
http://doc.qt.nokia.com/4.6/sql-driver.html#supported-databases